_msize in unix

Dec 29, 2011 at 8:14pm
I want to retrieve the size of a memory allocated by malloc
however g++ compiler does not regonize it.
‘_msize’ was not declared in this scope
I have included the following headers
malloc.h
stdlib.h

On the web someone say to use msize or malloc_size. Both of them does not work.
Is there any solutions? -------- I dont like 'new'
Dec 29, 2011 at 8:37pm
There is no way to do this in standard C++

_msize is a Windows API extension
malloc_size is a MacOS extension
some other operating systems have their own extensions. Unix does not have one (although some Unix-compatible systems do)

What do you mean by "not liking" new? malloc and new do different things.

UPD: mallinfo() from <malloc.h> is commonly found on Unix systems (including Linux), but it does not give this information directly.
Last edited on Dec 29, 2011 at 8:47pm
Dec 29, 2011 at 10:45pm
It seems mallinfo() can not get the memory size for a specific array
What I want is like
char* p=(char* )malloc(sizeof(chr)*10);
then how to get the size of memory p points to on unix system?
Dec 30, 2011 at 4:10am
You don't. You store the size somewhere else, as follows:

1
2
vector<char> p(10);
cout << p.size() << endl;
Jan 3, 2012 at 4:24pm
That does not make sense. I am writing a class with pointer to char as one of its member.
why the _msize function was omitted?
Jan 4, 2012 at 2:16am
You should pass that information to the object, not have it "figure it out".
Topic archived. No new replies allowed.