Re: sizeof([ALLOCATED MEMORY])
- From: "Stephen Sprunk" <stephen@xxxxxxxxxx>
- Date: Thu, 4 May 2006 14:26:01 -0500
"Howard Hinnant" <howard.hinnant@xxxxxxxxx> wrote in message news:howard.hinnant-EED144.10183104052006@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
No matter what the growth strategy for capacity, its existence is a
major motivation for finding out the amount of memory actually
allocated. create_array_short(N) may request only N*sizeof(short)
bytes, but may receive slightly more than that (for alignment purposes
or whatever). If create_array_short(N) had some way to find out how
much memory it actually received, then it makes perfect sense to set
capacity to size_received/sizeof(short) instead of to N. It makes for
higher performing code in the average case.
You're over-optimizing here. If malloc() returns more memory than you asked for, when you expand the array, you'll get access to it. On average, you'll perform the same number of realloc()s with or without this optimization unless you're expanding by a very small amount each time, in which case a large fraction of your realloc()s will be no-ops for the implementation.
S
--
Stephen Sprunk "Stupid people surround themselves with smart
CCIE #3723 people. Smart people surround themselves with
K5SSS smart people who disagree with them." --Aaron Sorkin
*** Posted via a free Usenet account from http://www.teranews.com ***
.
- Follow-Ups:
- Re: sizeof([ALLOCATED MEMORY])
- From: Howard Hinnant
- Re: sizeof([ALLOCATED MEMORY])
- References:
- sizeof([ALLOCATED MEMORY])
- From: ballpointpenthief
- Re: sizeof([ALLOCATED MEMORY])
- From: Richard Heathfield
- Re: sizeof([ALLOCATED MEMORY])
- From: Howard Hinnant
- Re: sizeof([ALLOCATED MEMORY])
- From: "Nils O. Selåsdal"
- Re: sizeof([ALLOCATED MEMORY])
- From: Howard Hinnant
- sizeof([ALLOCATED MEMORY])
- Prev by Date: Re: printf headache
- Next by Date: Re: Incrementing a void pointer. Legal C99?
- Previous by thread: Re: sizeof([ALLOCATED MEMORY])
- Next by thread: Re: sizeof([ALLOCATED MEMORY])
- Index(es):
Relevant Pages
|