This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Determining the size of allocated memory from a pointer
- From: Ian Lance Taylor <iant at google dot com>
- To: Justin_10 <justi_10 at rediffmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 02 Aug 2010 07:25:34 -0700
- Subject: Re: Determining the size of allocated memory from a pointer
- References: <29324330.post@talk.nabble.com>
Justin_10 <justi_10@rediffmail.com> writes:
> I am doing image processing application in which i will be getting two
> things pointer and a memory size pointed by this pointer.
>
> So for each invocation down the line i have to pass this two parameters.
>
> Is it possible to know the size of memory from the pointer itself.
>
> Please suggest for suitable solutions.
>
> for eg msize on windows.
This is actually not a compiler issue. It depends on the code that you
are using to allocate memory. Many memory allocators do not record the
exact size of the memory block that you request; they only record the
size of the memory block that they allocate, which may be larger than
the amount you request. That is true of the memory allocator used by
glibc on GNU/Linux, for example. So in general there is no way to get
this information, unless you use your own memory allocator.
Ian