[Fwd: Re: [BusyBox] choice for reserving buffers]
Vladimir N. Oleynik
dzo at simtreas.ru
Thu Jan 25 15:32:41 UTC 2001
Tomi Ollila wrote:
> How about stack vs xmalloc vs global buffer in BSS? SO everyone may
> choose which is best for them. I also can see need for BSS vs stack,
> but in some cases xmalloc() might be best???
1) xmalloc vs stack
1a) stack best for small buffer with constant size (alloca() is
not good function)
1b) stack best if audited code on check recursion
2) malloc vs BSS
2a) BSS can have only constant size, malloc is dynamic allocator
2b) BSS is constant address - fast and small code
2c) malloc is very slow function
2d) malloc require auditing code on memory leak
In given Larry Doolittle patch, undoubtedly wins on all positions BSS.
> Btw how is this prezeroing done?
> when new memory is demand allocated, the area is also zeroed at
> the same time? How does `calloc()' do this? the same way?
> (If one does x = malloc(MEMSIZ); if (x) memset(x, 0, MEMSIZ);
> probably have to demand all the memory it wants to clear -- or
> is memset() somehow smart here ?).
You have forgotten one moment.
You have addressed to beginning BSS of the buffer and have written down
there 1 byte. The kernel will allocate to you _one_ page
of clean memory (and quickly ;).
When you cause memset, you certainly will involve _all pages of memory_
at once as you in them write.
> Hmm, I'm tired of your impolite responses you are writing. I'd quess
> you're making some others too. Even you sound very skilled person,
> your replying style here doesn't help much?
Can be. It is very difficult for me to write in English.
--w
vodz
More information about the busybox
mailing list