Q:malloc

From: Michael Schuster (schusterSoccer_at_enertex.de)
Date: 05/27/04


Date: Thu, 27 May 2004 08:49:13 +0200

Hi,
I'm having a question referring malloc, refering to the docs of libc,
I found:
"The address of a block returned by `malloc' or `realloc' in the GNU
system is always a multiple of eight (or sixteen on 64-bit systems)"

Does this mean, if I compile:
        int *m1;
        m1=malloc(sizeof(int))
that the system occupates at least 8 (16 on a 64 Bit system) Words of
memory ?

So if my next instruction would be:
        int *m2;
        m2=malloc(sizeof(int))
my system would occupy already at least 16 (32) Bytes?

Also does the pointer allocation itself (int *m1 or int *m2) occupy
sizeof(int*) Bytes or at least 8 (or 16) Words?

I encountered the problem with my programm using a lot of void* - pointers
with only 1 element allocated with malloc. Due to my expirience (gcc (GCC)
3.3.3 (SuSE 9.1 Linux) ) with /proc/PID/status or top every malloc of an
void* needs at least 16 Bytes (or 4 32-Bit words). So in my programm the
system allocates the same space for
        int *m1;
        m1=malloc(sizeof(int))
and
        int *m1;
        m1=malloc(sizeof(int)*3)

Thanks for any comment!
Michael

-- 
Remove the sport from my address to obtain email
www.enertex.de - Innovative Systemlösungen der Energie- und Elektrotechnik


Relevant Pages

  • Re: large files: when ubiquitous?
    ... You don't need to malloc any ... The point of this particular subthread is that gcc is ... have written some broken code, ... And now you complain about gcc being so smart, ...
    (comp.os.linux.development.system)
  • conflicting types for malloc
    ... I cannot install mpack error "conflicting types for malloc" ... checking for gcc... ... checking whether the C compiler is a cross-compiler... ...
    (comp.os.linux.setup)
  • Re: malloc warning gcc > 4.0
    ... I know it works with gcc 3.3.6. ... as 'extern void *malloc;', but now it does. ... Because you did not #include, it assumes that the declaration of mallocis 'extern int malloc;', which is wrong. ... If you'd ever coded on an Motorola 680x0 machine, you'd know that pointers were returned in address registers and integers in the data registers, and mis-declaring malloc() and friends was a quick recipe for core dumps and other disasters. ...
    (comp.lang.c.moderated)
  • Re: gcc knows about malloc()
    ... I did "cast" malloc() rather than its ... the return value is assumed to be an int. ... Not by gcc, in sample code depicted. ...
    (comp.lang.c)
  • explicit constructor call on casted void *
    ... void pointer returned from a malloc(sizeof(class T)) which gives me ... this data as a class object, but the constructor hasnt been called which ... and am wondering whether someone can help me get it to work on gcc? ...
    (comp.lang.cpp)