_msize in unix

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'
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
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?
You don't. You store the size somewhere else, as follows:

1
2
vector<char> p(10);
cout << p.size() << endl;
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?
You should pass that information to the object, not have it "figure it out".
Topic archived. No new replies allowed.