When are shared library functions loaded into the heap?What and where are the stack and heap?Which is faster: Stack allocation or Heap allocationHow do function pointers in C work?How do I use extern to share variables between source files?Improve INSERT-per-second performance of SQLite?Difference between static and shared libraries?Issue with threads: value stored in heapInstruction Type and CountIs it possible to identify whether an address reference belongs to static/heap/stack in the process address spaceDeleting a heap variable giving munmap_chunk(): invalid pointer error
Using font to highlight a god's speech in dialogue
Inserting command output into multiline string
Is the mnemonic in Winter's Tale real?
Updating multiple vector points at once with vertex editor in QGIS?
Ways you can end up paying interest on a credit card if you pay the full amount back in due time
Why can't I summon my friend to help me?
Heuristic argument for the Riemann Hypothesis
Meaning of "educating the ice"
Calculate Landau's function
How Total raw is calculated for Science pack 2?
Babies - are we talking about their birth, arrival or delivery?
Received email from ISP saying one of my devices has malware
Why KVM VPS is slower then OPENVZ
Datasets of Large Molecules
Blogging in LaTeX
When making yogurt, why doesn't bad bacteria grow as well?
One hour 10 min layover in Newark; International -> Domestic connection. Enough time to clear customs?
How to check status of Wi-Fi adapter through command line?
Design of 50 ohms RF trace for 2.4GHz...Double layer FR-4 PCB
Function of the separated, individual solar cells on Telstar 1 and 2? Why were they "special"?
If the UK government illegally doesn't ask for article 50 extension, can parliament do it instead?
What is the definition of Product
Tiny image scraper for xkcd.com
Why did the VIC-II and SID use 6 µm technology in the era of 3 µm and 1.5 µm?
When are shared library functions loaded into the heap?
What and where are the stack and heap?Which is faster: Stack allocation or Heap allocationHow do function pointers in C work?How do I use extern to share variables between source files?Improve INSERT-per-second performance of SQLite?Difference between static and shared libraries?Issue with threads: value stored in heapInstruction Type and CountIs it possible to identify whether an address reference belongs to static/heap/stack in the process address spaceDeleting a heap variable giving munmap_chunk(): invalid pointer error
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
(This question concerns only the logical addresses)
I was experimenting with some code where I print out the addresses of different types/scopes of variables to better visualize the process image.
My confusion arose when I printed the addresses a few variables that have been allocated on the heap by malloc, and then also printed the address of the printf function out of curiosity.
What I discovered is that printf was being stored at a much higher address (ie closer to the stack) on the heap than my malloc allocated variables. This doesn't make sense to me because I assumed that the library functions would be loaded on the heap first thing at runtime before any other instructions are executed. I even put a printf statement before any malloc statements, in case library functions were loaded on the fly as they were needed, but it didn't change anything.
Thanks.
c memory heap
add a comment |
(This question concerns only the logical addresses)
I was experimenting with some code where I print out the addresses of different types/scopes of variables to better visualize the process image.
My confusion arose when I printed the addresses a few variables that have been allocated on the heap by malloc, and then also printed the address of the printf function out of curiosity.
What I discovered is that printf was being stored at a much higher address (ie closer to the stack) on the heap than my malloc allocated variables. This doesn't make sense to me because I assumed that the library functions would be loaded on the heap first thing at runtime before any other instructions are executed. I even put a printf statement before any malloc statements, in case library functions were loaded on the fly as they were needed, but it didn't change anything.
Thanks.
c memory heap
2
With virtual memory management, there's no reason to have any expectations about the addresses of the stack, heap, and code. And in fact, Address space layout randomization (ASLR) is specifically designed to foil attempts at predicting address relationships.
– user3386109
Mar 28 at 2:05
add a comment |
(This question concerns only the logical addresses)
I was experimenting with some code where I print out the addresses of different types/scopes of variables to better visualize the process image.
My confusion arose when I printed the addresses a few variables that have been allocated on the heap by malloc, and then also printed the address of the printf function out of curiosity.
What I discovered is that printf was being stored at a much higher address (ie closer to the stack) on the heap than my malloc allocated variables. This doesn't make sense to me because I assumed that the library functions would be loaded on the heap first thing at runtime before any other instructions are executed. I even put a printf statement before any malloc statements, in case library functions were loaded on the fly as they were needed, but it didn't change anything.
Thanks.
c memory heap
(This question concerns only the logical addresses)
I was experimenting with some code where I print out the addresses of different types/scopes of variables to better visualize the process image.
My confusion arose when I printed the addresses a few variables that have been allocated on the heap by malloc, and then also printed the address of the printf function out of curiosity.
What I discovered is that printf was being stored at a much higher address (ie closer to the stack) on the heap than my malloc allocated variables. This doesn't make sense to me because I assumed that the library functions would be loaded on the heap first thing at runtime before any other instructions are executed. I even put a printf statement before any malloc statements, in case library functions were loaded on the fly as they were needed, but it didn't change anything.
Thanks.
c memory heap
c memory heap
asked Mar 28 at 1:51
Luke4211Luke4211
143 bronze badges
143 bronze badges
2
With virtual memory management, there's no reason to have any expectations about the addresses of the stack, heap, and code. And in fact, Address space layout randomization (ASLR) is specifically designed to foil attempts at predicting address relationships.
– user3386109
Mar 28 at 2:05
add a comment |
2
With virtual memory management, there's no reason to have any expectations about the addresses of the stack, heap, and code. And in fact, Address space layout randomization (ASLR) is specifically designed to foil attempts at predicting address relationships.
– user3386109
Mar 28 at 2:05
2
2
With virtual memory management, there's no reason to have any expectations about the addresses of the stack, heap, and code. And in fact, Address space layout randomization (ASLR) is specifically designed to foil attempts at predicting address relationships.
– user3386109
Mar 28 at 2:05
With virtual memory management, there's no reason to have any expectations about the addresses of the stack, heap, and code. And in fact, Address space layout randomization (ASLR) is specifically designed to foil attempts at predicting address relationships.
– user3386109
Mar 28 at 2:05
add a comment |
1 Answer
1
active
oldest
votes
(This answer concerns Unix only. I don't know how it is on Windows.)
Most shared libraries are loaded into RAM before control reaches main, and the library containing printf definitely will be. The functions in dlfcn.h can be used to load more shared libraries during execution of the program, that's the most important exception.
Shared libraries have never been loaded as part of the "heap", if by that you mean the region of memory used to satisfy malloc requests. They are loaded using the system primitive mmap, and could be placed anywhere at all in memory. As user3386109 pointed out in a comment on the question, on modern systems, their locations are intentionally randomized as a countermeasure for various exploits.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389035%2fwhen-are-shared-library-functions-loaded-into-the-heap%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
(This answer concerns Unix only. I don't know how it is on Windows.)
Most shared libraries are loaded into RAM before control reaches main, and the library containing printf definitely will be. The functions in dlfcn.h can be used to load more shared libraries during execution of the program, that's the most important exception.
Shared libraries have never been loaded as part of the "heap", if by that you mean the region of memory used to satisfy malloc requests. They are loaded using the system primitive mmap, and could be placed anywhere at all in memory. As user3386109 pointed out in a comment on the question, on modern systems, their locations are intentionally randomized as a countermeasure for various exploits.
add a comment |
(This answer concerns Unix only. I don't know how it is on Windows.)
Most shared libraries are loaded into RAM before control reaches main, and the library containing printf definitely will be. The functions in dlfcn.h can be used to load more shared libraries during execution of the program, that's the most important exception.
Shared libraries have never been loaded as part of the "heap", if by that you mean the region of memory used to satisfy malloc requests. They are loaded using the system primitive mmap, and could be placed anywhere at all in memory. As user3386109 pointed out in a comment on the question, on modern systems, their locations are intentionally randomized as a countermeasure for various exploits.
add a comment |
(This answer concerns Unix only. I don't know how it is on Windows.)
Most shared libraries are loaded into RAM before control reaches main, and the library containing printf definitely will be. The functions in dlfcn.h can be used to load more shared libraries during execution of the program, that's the most important exception.
Shared libraries have never been loaded as part of the "heap", if by that you mean the region of memory used to satisfy malloc requests. They are loaded using the system primitive mmap, and could be placed anywhere at all in memory. As user3386109 pointed out in a comment on the question, on modern systems, their locations are intentionally randomized as a countermeasure for various exploits.
(This answer concerns Unix only. I don't know how it is on Windows.)
Most shared libraries are loaded into RAM before control reaches main, and the library containing printf definitely will be. The functions in dlfcn.h can be used to load more shared libraries during execution of the program, that's the most important exception.
Shared libraries have never been loaded as part of the "heap", if by that you mean the region of memory used to satisfy malloc requests. They are loaded using the system primitive mmap, and could be placed anywhere at all in memory. As user3386109 pointed out in a comment on the question, on modern systems, their locations are intentionally randomized as a countermeasure for various exploits.
answered Mar 28 at 2:13
zwolzwol
104k27 gold badges184 silver badges287 bronze badges
104k27 gold badges184 silver badges287 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389035%2fwhen-are-shared-library-functions-loaded-into-the-heap%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
With virtual memory management, there's no reason to have any expectations about the addresses of the stack, heap, and code. And in fact, Address space layout randomization (ASLR) is specifically designed to foil attempts at predicting address relationships.
– user3386109
Mar 28 at 2:05