Re: No need to optimize in assembly anymore

From: Ivan Korotkov (koroNOSPAMtkov2_at_ztelDOT.ru)
Date: 05/23/04


Date: Sun, 23 May 2004 18:04:05 +0000 (UTC)


> Okay, do you claim that variables and functions inside classes are
> better than container classes and STL? You would want to avoid malloc or
> new function if it is less than 1MB.

He didn't tell this exact value.

> It is not really necessary to use
> malloc or new functions if memory is not very big.
> What is the minimum MB that malloc or new function should be used? I
> suspect 10MB.?????

What's the minimum number of hairs to form a beard? I would stop at few
kilobytes (of memory, not of hairs :)). Allocating more than 4KB on stack
cannot be done by just substracting from esp (on Windows at least, don't
know how *nix organizes stack). Otherwise, stack pointer will bypass the
guardian page and fall into reserved memory space. Compiler calls a special
function (_chkstk, IIRC) which allocates memory on stack page-by-page. This
will cause as many page faults and transitions as many pages you allocate.
Thus, the efficiency of stack allocations is limited not by the memory waste
but by the time that PF handler requires to handle so many page faults.
Let's imagine that you allocate 10MB of memory (it is 10 times more than the
default stack reserve, but you have set it to 15MB). That will cause 2560
page faults. P4 @ 2.4GHz needs about 0.9ms to call the interrupt handler so
many times. And the handler itself requires some time. So it will take about
a few milliseconds. I think it's *much* slower then calling malloc.

> Is it true that malloc or new function is never used if segments are
> used instead of flat model under 640KB?

Who - told - you - that?

> It sounds like malloc or new
> function uses to allocate virtual memory,

Under Windows.

> but below 640KB does not.

Does. Under DOS.

Ivan



Relevant Pages

  • Re: run-time vs compile-time
    ... > offset related to some location (like stack base) somewhere. ... > offset from heap to pi. ... When you allocate an int on the heap, it is allocated at address 1. ... application has a given amount of memory it can use as it wishes. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: run-time vs compile-time
    ... > offset related to some location (like stack base) somewhere. ... > offset from heap to pi. ... When you allocate an int on the heap, it is allocated at address 1. ... application has a given amount of memory it can use as it wishes. ...
    (comp.lang.cpp)
  • Re: Review: My C FAQ Page
    ... the definition of memory leak is good but the information on ... this is not the most efficient way to allocate the 2-d array. ... You have ROW+1 calls to malloc. ... Allocate ROW pointers. ...
    (comp.lang.c)
  • Re: ten thousand small processes
    ... Stack needs to be executable for the current signal trampoline ... the use of malloc() that is causing your primary ... if there is any heap memory in use at all, no matter what you do, ... either directly, as a 4M page mapping (not used for user processes, ...
    (freebsd-performance)
  • Re: Doubt on Stack variables.
    ... Will it allocate memory for all the char's together or allocate for ... this only second char in the function gets memory. ... As other posters have pointed out, the notion of a "stack" does not appear ... the stack limits) would run into these limits. ...
    (comp.lang.c)