Fedora Linux Support Community & Resources Center
  #1  
Old 3rd February 2012, 04:05 PM
demon007 Offline
Registered User
 
Join Date: Sep 2011
Posts: 2
linuxchrome
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
  #2  
Old 3rd February 2012, 04:55 PM
Gareth Jones Offline
Official Gnome 3 Sales Rep. (and Adminstrator)
 
Join Date: Jul 2011
Location: Leamington Spa, UK
Age: 31
Posts: 2,750
linuxfirefox
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.)

Gareth
Reply With Quote
  #3  
Old 3rd February 2012, 05:37 PM
jpollard Online
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,790
linuxfedorafirefox
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 05:39 PM.
Reply With Quote
Reply

Tags
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 09:43 PM
Wants to change allocated memory SunilReddy Installation, Upgrades and Live Media 3 31st December 2007 06:36 PM


Current GMT-time: 06:34 (Saturday, 02-08-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

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