How does Haskell manage its memory?
up vote
1
down vote
favorite
1
So, we know that for most languages, throughout a program's execution:
- Global variables are stored in static memory.
- Local variables are stored in the stack memory.
- Arbitrarily-changing variables are stored in the heap.
What about Haskell? All I know is that it is lazy. How does that translate into this context?
haskell memory-management functional-programming ghc
New contributor
add a comment |
up vote
1
down vote
favorite
1
So, we know that for most languages, throughout a program's execution:
- Global variables are stored in static memory.
- Local variables are stored in the stack memory.
- Arbitrarily-changing variables are stored in the heap.
What about Haskell? All I know is that it is lazy. How does that translate into this context?
haskell memory-management functional-programming ghc
New contributor
5
Well a lot of (high-level) languages keep it open how memory management is implemented. But for GHC, this wiki page might be a start.
– Willem Van Onsem
2 days ago
3
As a zeroth-order approximation you'd have to say that everything is on the heap in Haskell, but more practically we can assume that the compiler will decide to put any variable whereever it's deemed best for performance. Quite often it will also eliminate variables entirely, or introduce new ones. All that the language specifies is that you'll get the right results in the end...
– leftaroundabout
2 days ago
2
Don't forget that static/stack/heap memory does not really exist on its own. At the lower level, we only have RAM (including virtual memory). Then the OS may reserve a portion of the address space for the "stack", allow processes to request more stack (e.g.sbrk
) or heap (mmap
), and pre-allocating a static portion when the executable is loaded. The the language runtime system can, on top of this, use garbage collection. Some variants of GC further divide the memory into generations or from-space/to-space (for copying GCs). These are further abstractions, usually implemented in the "heap"
– chi
2 days ago
2
Haskell doesn't say anything about memory management. A particular implementation of Haskell makes those decisions.
– chepner
2 days ago
add a comment |
up vote
1
down vote
favorite
1
up vote
1
down vote
favorite
1
1
So, we know that for most languages, throughout a program's execution:
- Global variables are stored in static memory.
- Local variables are stored in the stack memory.
- Arbitrarily-changing variables are stored in the heap.
What about Haskell? All I know is that it is lazy. How does that translate into this context?
haskell memory-management functional-programming ghc
New contributor
So, we know that for most languages, throughout a program's execution:
- Global variables are stored in static memory.
- Local variables are stored in the stack memory.
- Arbitrarily-changing variables are stored in the heap.
What about Haskell? All I know is that it is lazy. How does that translate into this context?
haskell memory-management functional-programming ghc
haskell memory-management functional-programming ghc
New contributor
New contributor
edited 12 hours ago
Benjamin Hodgson♦
26.2k1172121
26.2k1172121
New contributor
asked 2 days ago
thlik
93
93
New contributor
New contributor
5
Well a lot of (high-level) languages keep it open how memory management is implemented. But for GHC, this wiki page might be a start.
– Willem Van Onsem
2 days ago
3
As a zeroth-order approximation you'd have to say that everything is on the heap in Haskell, but more practically we can assume that the compiler will decide to put any variable whereever it's deemed best for performance. Quite often it will also eliminate variables entirely, or introduce new ones. All that the language specifies is that you'll get the right results in the end...
– leftaroundabout
2 days ago
2
Don't forget that static/stack/heap memory does not really exist on its own. At the lower level, we only have RAM (including virtual memory). Then the OS may reserve a portion of the address space for the "stack", allow processes to request more stack (e.g.sbrk
) or heap (mmap
), and pre-allocating a static portion when the executable is loaded. The the language runtime system can, on top of this, use garbage collection. Some variants of GC further divide the memory into generations or from-space/to-space (for copying GCs). These are further abstractions, usually implemented in the "heap"
– chi
2 days ago
2
Haskell doesn't say anything about memory management. A particular implementation of Haskell makes those decisions.
– chepner
2 days ago
add a comment |
5
Well a lot of (high-level) languages keep it open how memory management is implemented. But for GHC, this wiki page might be a start.
– Willem Van Onsem
2 days ago
3
As a zeroth-order approximation you'd have to say that everything is on the heap in Haskell, but more practically we can assume that the compiler will decide to put any variable whereever it's deemed best for performance. Quite often it will also eliminate variables entirely, or introduce new ones. All that the language specifies is that you'll get the right results in the end...
– leftaroundabout
2 days ago
2
Don't forget that static/stack/heap memory does not really exist on its own. At the lower level, we only have RAM (including virtual memory). Then the OS may reserve a portion of the address space for the "stack", allow processes to request more stack (e.g.sbrk
) or heap (mmap
), and pre-allocating a static portion when the executable is loaded. The the language runtime system can, on top of this, use garbage collection. Some variants of GC further divide the memory into generations or from-space/to-space (for copying GCs). These are further abstractions, usually implemented in the "heap"
– chi
2 days ago
2
Haskell doesn't say anything about memory management. A particular implementation of Haskell makes those decisions.
– chepner
2 days ago
5
5
Well a lot of (high-level) languages keep it open how memory management is implemented. But for GHC, this wiki page might be a start.
– Willem Van Onsem
2 days ago
Well a lot of (high-level) languages keep it open how memory management is implemented. But for GHC, this wiki page might be a start.
– Willem Van Onsem
2 days ago
3
3
As a zeroth-order approximation you'd have to say that everything is on the heap in Haskell, but more practically we can assume that the compiler will decide to put any variable whereever it's deemed best for performance. Quite often it will also eliminate variables entirely, or introduce new ones. All that the language specifies is that you'll get the right results in the end...
– leftaroundabout
2 days ago
As a zeroth-order approximation you'd have to say that everything is on the heap in Haskell, but more practically we can assume that the compiler will decide to put any variable whereever it's deemed best for performance. Quite often it will also eliminate variables entirely, or introduce new ones. All that the language specifies is that you'll get the right results in the end...
– leftaroundabout
2 days ago
2
2
Don't forget that static/stack/heap memory does not really exist on its own. At the lower level, we only have RAM (including virtual memory). Then the OS may reserve a portion of the address space for the "stack", allow processes to request more stack (e.g.
sbrk
) or heap (mmap
), and pre-allocating a static portion when the executable is loaded. The the language runtime system can, on top of this, use garbage collection. Some variants of GC further divide the memory into generations or from-space/to-space (for copying GCs). These are further abstractions, usually implemented in the "heap"– chi
2 days ago
Don't forget that static/stack/heap memory does not really exist on its own. At the lower level, we only have RAM (including virtual memory). Then the OS may reserve a portion of the address space for the "stack", allow processes to request more stack (e.g.
sbrk
) or heap (mmap
), and pre-allocating a static portion when the executable is loaded. The the language runtime system can, on top of this, use garbage collection. Some variants of GC further divide the memory into generations or from-space/to-space (for copying GCs). These are further abstractions, usually implemented in the "heap"– chi
2 days ago
2
2
Haskell doesn't say anything about memory management. A particular implementation of Haskell makes those decisions.
– chepner
2 days ago
Haskell doesn't say anything about memory management. A particular implementation of Haskell makes those decisions.
– chepner
2 days ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
thlik is a new contributor. Be nice, and check out our Code of Conduct.
draft saved
draft discarded
thlik is a new contributor. Be nice, and check out our Code of Conduct.
thlik is a new contributor. Be nice, and check out our Code of Conduct.
thlik is a new contributor. Be nice, and check out our Code of Conduct.
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238460%2fhow-does-haskell-manage-its-memory%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
5
Well a lot of (high-level) languages keep it open how memory management is implemented. But for GHC, this wiki page might be a start.
– Willem Van Onsem
2 days ago
3
As a zeroth-order approximation you'd have to say that everything is on the heap in Haskell, but more practically we can assume that the compiler will decide to put any variable whereever it's deemed best for performance. Quite often it will also eliminate variables entirely, or introduce new ones. All that the language specifies is that you'll get the right results in the end...
– leftaroundabout
2 days ago
2
Don't forget that static/stack/heap memory does not really exist on its own. At the lower level, we only have RAM (including virtual memory). Then the OS may reserve a portion of the address space for the "stack", allow processes to request more stack (e.g.
sbrk
) or heap (mmap
), and pre-allocating a static portion when the executable is loaded. The the language runtime system can, on top of this, use garbage collection. Some variants of GC further divide the memory into generations or from-space/to-space (for copying GCs). These are further abstractions, usually implemented in the "heap"– chi
2 days ago
2
Haskell doesn't say anything about memory management. A particular implementation of Haskell makes those decisions.
– chepner
2 days ago