|
|
Size of Allocated Memory
I have a function that returns a int pointer to a allocated memory.
How I know the size of this allocated memory?
Compiler = gcc
Ex.:
int main(void)
{
int *pointer;
pointer = fakefunc();
/* How I know the size of allocated memory?? */
return 0;
}
|
|
0
|
|
|
|
Reply
|
mandark (1)
|
5/6/2004 3:54:42 PM |
|
mandark_br <mandark@rockpesado.com.br> wrote:
> I have a function that returns a int pointer to a allocated memory.
> How I know the size of this allocated memory?
> int main(void)
> {
> int *pointer;
> pointer = fakefunc();
> /* How I know the size of allocated memory?? */
By simply storing it when you allocate the memory and then
returning it from fakefunc() together with the pointer.
There's no standard function that would give you that
information just from the pointer.
> Compiler = gcc
The compiler is completely irrelevant. If you're looking
for a non-portable solution you will have to check if the
libc you're using has an extension for doing that because
the libc is where malloc() and friends are defined.
Regards. Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
|
|
0
|
|
|
|
Reply
|
Jens.Toerring (807)
|
5/6/2004 4:01:05 PM
|
|
mandark_br wrote:
>
> I have a function that returns a int pointer to a allocated memory.
> How I know the size of this allocated memory?
This is Question 7.27 in the comp.lang.c Frequently
Asked Questions (FAQ) list
http://www.eskimo.com/~scs/C-faq/top.html
.... and you may want to look at Question 7.26 also. You
won't like the answers, though.
--
Eric.Sosman@sun.com
|
|
0
|
|
|
|
Reply
|
Eric.Sosman (4228)
|
5/6/2004 4:06:20 PM
|
|
mandark_br <mandark@rockpesado.com.br> wrote:
> I have a function that returns a int pointer to a allocated memory.
> How I know the size of this allocated memory?
> Compiler = gcc
> Ex.:
> int main(void)
> {
> int *pointer;
> pointer = fakefunc();
> /* How I know the size of allocated memory?? */
> return 0;
> }
You can't, and you shouldn't need to. It is your responsibility to keep
track of how much memory 'fakefunc' allocates. If you can't do that in
your context, then show us a more concrete example.
--
Alex Monjushko (monjushko@hotmail.com)
|
|
0
|
|
|
|
Reply
|
monjushko (45)
|
5/6/2004 4:39:08 PM
|
|
|
3 Replies
39 Views
(page loaded in 0.085 seconds)
Similiar Articles: How to check whether malloc has allocated memory properly in case ...i want to check after calling malloc whether allocation is successful or not. previously i have done like ptr=malloc(size); if(ptr==NULL) Bu... the maximum memory size allowed in malloc - comp.lang.cHow do I determine the size (preferably layout) of the stack frame of a ... How to check whether malloc has allocated memory properly in case ... top: SIZE and RES - comp.sys.hp.hpuxMy understanding is that SIZE is the total amount of virtual memory allocated to a process and RES is how much is actually paged in at the time. This... Allocating Memory in DOS - comp.lang.asm.x86... system memory is allocated ... file size is a multiple of 16 bytes). ADD BX,0FH >SHR BX,4 >INT 21H > >;Now AX should hold the segment address of the allocated memory ... Allocatable versus automatic arrays - comp.lang.fortranIn sum, I think my doubts reduce to the question of whether the efficiency of accessing the physical memory depends on the size of the allocated memory, or if it is ... Allocating, Deallocating and Reallocating - comp.lang.fortran ...C has realloc() that, on most unix and unix-like systems, has the possibility of increasing the size in place. If the array is at the end of allocated memory it can ... Maximum shared memory segment size - comp.unix.solaris... Generic_127111-11 sun4v sparc SUNW,SPARC-Enterprise-T5220 Total shared memory size ... never wastes memory. >> >> I have seen it where the share mem is so over allocated ... Allocating memory for Option ROM during BIOS POST and bootloader ...Yes I understand that new EBDA allocation after my driver will adjust available system memory size at 0x413 but it will also move down the original allocated memory ... get virtual memory size of process? - comp.unix.programmer ...top: SIZE and RES - comp.sys.hp.hpux My understanding is that SIZE is the total amount of virtual memory allocated to a process and RES is how much is actually paged in at ... how much memory does an empty STL deque occupy? - comp.lang.c++ ...... arrays that allocate memory dynamically (and there is some dynamic memory allocation inside of a deque class, isn't it?) so i figured it wouldn't give me correct size ... C dynamic memory allocation - Wikipedia, the free encyclopediaAllocated memory contains an 8 or 16 byte overhead for the size of the chunk and usage flags. Unallocated chunks also store pointers to other free chunks in the usable ... Memory Allocation - eCosCentric - the eCos embedded real-time ...void* malloc(size_t size); void* calloc(size_t nmemb, size_t size); void* realloc(void* ptr, size_t size); void free(void* ptr); struct mallinfo mallinfo(void); 7/8/2012 12:34:16 PM
|
|
|
|
|
|
|
|
|