Fedora Linux Support Community & Resources Center
Old 3rd February 2012, 05:05 PM
demon007 Offline
Registered User
Join Date: Sep 2011
Posts: 2
Memory map or physical address of some memory allocated by malloc

How can I get the memory map or physical address of some memory allocated by malloc?

Please help me. I cannot get it anywhere.

Thanks in advance.
Reply With Quote
Old 3rd February 2012, 05:55 PM
Gareth Jones Offline
Retired Adminstrator
Join Date: Jul 2011
Location: Birmingham, UK
Age: 34
Posts: 2,761
Re: Memory map or physical address of some memory allocated by malloc

Get virtual address (void*), check /proc/self/maps, check /proc/self/pagemap. See this post: http://stackoverflow.com/a/6261020 for an explanation.

Remember to lock the page first, or the virtual memory system could change the mapping at any time. Also ask yourself why you want to do that. If hardware memory addresses matter for your code, you should probably be writing a kernel module. (If you are writing kernel code, check the other answers on the linked page, I'm not familiar with kernel internals myself but someone else may know.)

Reply With Quote
Old 3rd February 2012, 06:37 PM
jpollard Offline
Registered User
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 7,346
Re: Memory map or physical address of some memory allocated by malloc

Also remember that a single malloc call can allocate multiple pages, and such memory maps can/will be scattered all over. And the next run will have a different map.

What you are asking for is almost never useful unless you are debugging some kernel process startup.

Also remember - malloc doesn't have to actually allocate anything. All it does is record that you asked.

Such memory is only allocated WHEN the memory page is actually written to.

BTW, another problem occurs when memory is reallocated (you used it, and released it). Such allocations do not have to alter the processes page structure at all. The memory "allocated" may actually be in swap, and again, doesn't really exist until it is written to.

Last edited by jpollard; 3rd February 2012 at 06:39 PM.
Reply With Quote

address, allocated, malloc, map, memory, physical

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How much memory is allocated? johnnytda Programming & Packaging 4 26th January 2012 10:43 PM
Wants to change allocated memory SunilReddy Installation, Upgrades and Live Media 3 31st December 2007 07:36 PM

Current GMT-time: 15:25 (Friday, 22-09-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat