optimum malloc size

optimum malloc size

Post by joh.. » Thu, 16 Dec 1999 04:00:00



I have a record size of 29 bytes and I want
to malloc a buffer to hold an unknown number
of records. When that buffer gets full, realloc
another block on.

What is the optimum buffer size to malloc.
Is it best to malloc in 1K size blocks, the system page size or
something else?

Specifics
---------
OS       : Solaris 2.5.1
Page Size: 8192 bytes

Any input would be appreciated!

John

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

optimum malloc size

Post by Kenneth C Stah » Thu, 16 Dec 1999 04:00:00



> I have a record size of 29 bytes and I want
> to malloc a buffer to hold an unknown number
> of records. When that buffer gets full, realloc
> another block on.

> What is the optimum buffer size to malloc.
> Is it best to malloc in 1K size blocks, the system page size or
> something else?

> Specifics
> ---------
> OS       : Solaris 2.5.1
> Page Size: 8192 bytes

> Any input would be appreciated!

> John

> Sent via Deja.com http://www.deja.com/
> Before you buy.

I'd suggest using BUFSIZ from stdlib.h. On most systems it is either 512 or
1024, but if you use the header file definition you will be more portable
than if you specify a literal value yourself.

 
 
 

optimum malloc size

Post by Keith Thompso » Thu, 16 Dec 1999 04:00:00



[...]

Quote:> I'd suggest using BUFSIZ from stdlib.h. On most systems it is either 512 or
> 1024, but if you use the header file definition you will be more portable
> than if you specify a literal value yourself.

BUFSIZ is in stdio.h, not stdlib.h.

Note that this is the size of an I/O buffer.  It's not clear (to me)
that this will be the most efficient size for malloc, though it's
likely not to be terribly inefficient.

Suggestion: Try several different values and do some profiling.

--

San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
"Oh my gosh!  You are SO ahead of your time!" -- anon.

 
 
 

1. does realloc(NULL,size) work like malloc(size) on SunOS 4.1.3 or AIX 2

%% Regarding [Q] does realloc(NULL,size) work like malloc(size) on SunOS

    cz> has anyone noticed that realloc(NULL,size) does not work like
    cz> malloc(size) on SunOS 4.1.3 or AIX 2? the man page for realloc()
    cz> claims that realloc() should act like malloc when it gets a NULL
    cz> ptr.

Whose man page?  Not SunOS's anyway, not on my SunOS 4.1.3_U1 :)

According to ANSI C, conforming implementations of the C runtime library
should treat realloc(NULL,size) the same as malloc(size).

However, certainly no one's ever accused SunOS 4.1.x of having a C
runtime library that comes close to conforming to ANSI C (despite the
fact that it's been a standard for 7 years).  AIX 2 sounds old enough
that it also is suspect.
--
-------------------------------------------------------------------------------

 Senior Software Engineer                                   Bay Networks, Inc.
-----------------------------------------------==<http://www.baynetworks.com/>-
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
     These are my opinions--Bay Networks takes no responsibility for them.

2. Problem with math lib on linux

3. Optimum partition sizes, source files

4. IDE ATA66 supported?

5. Optimum filesystem size?

6. Two WANs

7. Optimum Hardware Cache size

8. pump failing to set hostname

9. Optimum log disk size for Veritas RAID-5

10. Optimum Paging Space Size

11. optimum size of TCP socket message?

12. optimum size of paging space for added RAM

13. optimum Size of /usr ?