Article View: borland.public.cppbuilder.nativeapi
Article #13363Installing New TMemoryManger
From: CC
Date: Fri, 17 Oct 2003 17:25
Date: Fri, 17 Oct 2003 17:25
51 lines
2189 bytes
2189 bytes
Greetings - From previous problems w/Borland MM and previous post
suggestions, I'm playing with installing a new Tmemory manager, using just
the very basic Win API memory allocation functions (I'm sure it's greatly
inefficient, but just for testing/learning purposes).
My program NEVER starts up with my new 'cheap' mem mgr.
I was wondering if anyone could tell me what I'm doing wrong,
Thanks for the help: heres the cheap stab at mem mgr code:
// VARIABLES FOR OLD & NEW MMGR
TMemoryManager mmNew;
TMemoryManager mmOld;
// DECLARE ALLOC,REALLOC,FREE Functions for new mem mgr
void* __fastcall MyGetMem(int nbytes)
{
HGLOBAL memptr;
memptr= GlobalAlloc(GMEM_MOVEABLE ,nbytes);
return memptr;
}
int __fastcall MyFreeMem(void *p)
{
if(GlobalFree(p)==NULL)
return 0;
return 1;
}
void* __fastcall MyReallocMem(void *p, int nbytes)
{
HGLOBAL memptr;
memptr=GlobalReAlloc( p, nbytes, GMEM_ZEROINIT);
return memptr;
}
//---- SET THE NEW MEM MGR in WinMain()
try {
mmNew.GetMem=MyGetMem;
mmNew.FreeMem=MyFreeMem;
mmNew.ReallocMem=MyReallocMem;
GetMemoryManager(mmOld);
SetMemoryManager(mmNew);
// Do normal app startup......
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
Technical Details
Message-ID:
<3f9025f1$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.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-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ee2b0dd0938897eb,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-10-17 10:39:43 PST From: "CC" <Xcurtc@tmscorp.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Installing New TMemoryManger Date: Fri, 17 Oct 2003 12:25:46 -0500 Lines: 54 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 208.254.250.201 Message-ID: <3f9025f1$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1066411505 208.254.250.201 (17 Oct 2003 10:25:05 -0700) Path: arc1-ca.pugleaf.net!archiver1.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