🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8603

Re: malloc: where is the catch?

#8603
From: Bob Gonder
Date: Thu, 07 Oct 2004 16:49
38 lines
2061 bytes

Might be interesting to add

GlobalFree( GlobalAlloc( GMEM_FIXED, 0x2000 ) );
GlobalFree( GlobalAlloc( GMEM_FIXED|GMEM_ZEROINIT, 0x2000 ) );
GlobalFree( GlobalAlloc( GMEM_MOVEABLE, 0x2000 ) );
GlobalFree( GlobalAlloc( GMEM_MOVEABLE|GMEM_ZEROINIT, 0x2000 ) );

 to your tests.
And then, you could add the GMEM_NOCOMPACT flag to the above to see if
they go any faster.

But, if you want to get closer to the speed of malloc, then this sort
of thing should help:

(Allocates 81,920,000 bytes)
char*array[10000];
void*memory[10000/16];
for( int i=0; i<10000/16; ++i )
{	memory[i] = GlobalAlloc( GMEM_FIXED,16*0x2000);
	for( int j=0; j<16; ++j )
		array[i*16+j] = (char*)memory[i];
};

As i understand it, this is what malloc does, only bigger and more
complicated.

You might rewrite your test for a more real-world experience.
Inside a 2,000 timing loop,
{	/* Maximum garbage generation */
   {Allocate 1000 random size allocations}
   {Randomly free the allocations}
}
Random Free might be simple, like
	for( int i=0; i<13; ++i )
		for( int k=i; k<1000; k+=13 )
			free( array[k] );
Technical Details
Message-ID: <tiqam019j4cp7ud1i2j6s1ef1e04nl6fag@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4165469c$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,50f14b41a5262fc0
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: malloc: where is the catch?
Date: Thu, 07 Oct 2004 09:49:37 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <tiqam019j4cp7ud1i2j6s1ef1e04nl6fag@4ax.com>
References: <4165469c$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.34.193.40
X-Trace: newsgroups.borland.com 1097167775 69.34.193.40 (7 Oct 2004 09:49:35 -0700)
Lines: 40
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail