- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Size of memory block pointed by a pointer?how to g...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2009 09:29 PM
тАО10-20-2009 09:29 PM
Am new to HP UX , is there a way to find out the size of memory allocated to a pointer on hp ux?
For example we can use the _msize() on windows to find the size of memory allocated to a pointer .
#include
#include
void main()
{
void *buffer;
buffer = malloc( 999 );
printf( "Size of block is %u bytes\n", _msize( buffer ) );
}
produces the output:
Size of block is 1000 bytes
Is there any way this can be done on HP UX too?
Thank you very much in advance.
Regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2009 09:52 PM
тАО10-20-2009 09:52 PM
Re: Size of memory block pointed by a pointer?how to get it?
malloc_usable_size(void*)
in malloc.h header file which does return the number of bytes to which a pointer i pointing, but it returns the
bytes allocated by malloc + some padding value.
It wont return the exact value allocated.
Reason why i ask this question is :
There is this millions of lines of code for which we dont know how many thousands of mallocs are called.
The easy way out could have been to create a Vector class type of object and maintain a size allocated by malloc by writing this in the wrapper for malloc..
But since the code was written years ago things aint that flexible .
and hence the reason :)
Thanks again :D
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2009 12:22 AM
тАО10-21-2009 12:22 AM
SolutionThere is no documented way to get it.
>in malloc.h header file
Where? What OS version?
>It wont return the exact value allocated.
This is close enough.
>we don't know how many thousands of mallocs are called.
You could use wdb's "info heap" command to give you what is currently allocated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2009 12:32 AM
тАО10-21-2009 12:32 AM
Re: Size of memory block pointed by a pointer?how to get it?
Coding is being done in C.
Thanks a lot for reply Dennis :)
Helped me a lot
Regards :D
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2009 12:57 AM
тАО10-21-2009 12:57 AM
Re: Size of memory block pointed by a pointer?how to get it?
> bytes allocated by malloc + some padding
> value.
>
> It wont return the exact value allocated.
Perhaps it returns the exact value
_allocated_, which may differ from the exact
value _requested_.
You could write your own malloc()+free(),
which could remember+forget more.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2009 02:42 AM
тАО10-21-2009 02:42 AM
Re: Size of memory block pointed by a pointer?how to get it?
More memory is allocated than what is requested.
Observation:
if 1*sizeof(int) is allocated it returns 28 bytes
if 4*sizeof(int) is allocated it returns 28
for bigger values of 100s , 1000s and 10000s of sizeof(int), it returned the exact value requested for + 12 bytes.
Thanks and Regards :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2009 06:25 AM
тАО10-21-2009 06:25 AM
Re: Size of memory block pointed by a pointer?how to get it?
All malloc implementations have control area, before the returned address where the requested or allocated size is stored. Otherwise the 'free' would need to provide that.
The overhead is typically padded to make sure that the first databyte is aligned 'nicely' in memory. (16 bytes for many architectures)
The allocation is also rounded up.
>> if 1*sizeof(int) is allocated it returns 28 bytes
if 4*sizeof(int) is allocated it returns 28
Right. There is no point in doing a malloc for just 1 integer as it takes more space for the application to hold the pointer than it takes to hold the value.
>> for bigger values of 100s , 1000s and 10000s of sizeof(int), it returned the exact value requested for + 12 bytes.
That's probably because you asked for nice 'round (2-squared) numbers. Allocate something 'odd' and more fudge factor will appear.
The EXACT behavior depends on the malloc code used which on HP UX can be tweaked using the 'mallopt' call.
Check out the man page for mallopt, and be sure to check out 'mallinfo' while you are there as well.
Enjoy,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2009 08:53 PM
тАО10-21-2009 08:53 PM
Re: Size of memory block pointed by a pointer?how to get it?
And yes ofcourse as I haggered the value of the number of sizeof(int), I got a variation of padded value from +8 to +16 or so.
Thanks a lot for your Valuable input Hein.
Helped a lot :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-22-2009 02:03 AM
тАО10-22-2009 02:03 AM
Re: Size of memory block pointed by a pointer?how to get it?
mallopt(3) also has a small block allocator that allocates lots of space for N blocks.
There are thread arenas and there is a new product for 11.31, MallocNG.
On Integrity, malloc returns 16 byte aligned, vs 8 for PA.