delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/25/17:30:16

Message-ID: <360C0F4E.4BC28D4C@mailexcite.com>
Date: Fri, 25 Sep 1998 17:46:55 -0400
From: Doug Gale <dgale AT mailexcite DOT com>
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Memory allocation!
References: <Pine DOT SUN DOT 3 DOT 96 DOT 980925165045 DOT 24651A-100000 AT athenas DOT ime DOT unicamp DOT br>
NNTP-Posting-Host: oshawappp34.idirect.com
Organization: "Usenet User"
Lines: 42
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp


Renato F. Cantao wrote:

> Hi SET!
>
> On Fri, 25 Sep 1998, Salvador Eduardo Tropea (SET) wrote:
>
> > "Renato F. Cantao" <cantao AT ime DOT unicamp DOT br> asked:
> >
> > >     I'm working on some mathematics implementations involving large
> > > amounts of memory allocation. So my questions are:
> > >
> > >     1. Operator "new" and "malloc" are speed-equivalent?
> >
> > Almost, new is a wrapper, so it makes some extra checks.
> >
> > >     2. Despite the answer, does exist a better (=faster!) way to
> > > allocate memory?
> >
> > Yes: do your own custom routine optimized for your allocation scheme! ;-)
> >
>
> OK, that's perfect. I'm meaning, does exist any other routine faster than
> new or malloc?
>
>                 Renato Fernandes CANTAO
>                 State University at Campinas
>                 Campinas - Brazil

Depends on how you are going to use the memory. If it is just scratch memory
(will be free'd before the function returns) use alloca(). Note that this uses
stack space for the allocation, but reduces it to a cycle or two. Oh, alloca is
not an ANSI C function. NOTE: the memory allocated this way can't be freed
until the function returns. Conversely, there is no way to stop it from being
freed when the function returns.

alloca is a builtin function that compiles to inline assembly.

Example, allocate 100 bytes: subl $100,%esp; movl %esp,_MyPointer


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019