Article View: borland.public.cppbuilder.nativeapi
Article #13217Global mem functions and threading
From: CC
Date: Mon, 20 Oct 2003 16:02
Date: Mon, 20 Oct 2003 16:02
60 lines
2345 bytes
2345 bytes
Greetings.
I have installed a very simple memory manager to call winapi
alloc,re-alloc,free routines (Global**() apis).
When I install the mem mgr in WinMain(), after Application->Initialize().
The mgr. seems to be working ok.
The application that uses this cut-down mem mgr does multiple threading with
TThread objects.
Is the Global***() mem functions thread safe? Can 2 threads call the Global
fucntions at same time without worrying about screwing memory up?
In the context of the memory manager, is it correct to assume that the tmem
mgr usage by the vcl is thread safe?
Thanks for the assistance,
CurtC
------ Simple mem mgr code below:
static TMemoryManager mmNew;
static TMemoryManager mmOld;
void* __fastcall MyGetMem(int nbytes)
{
HGLOBAL memptr = GlobalAlloc(GMEM_FIXED ,nbytes);
return (void*)memptr;
}
void* __fastcall MyReallocMem(void *p, int nbytes)
{
HGLOBAL memptr=GlobalReAlloc( p, nbytes, GMEM_ZEROINIT);
return (void*)memptr;
}
int __fastcall MyFreeMem(void *p)
{
if(p==NULL)return 0;
if(GlobalFree(p)==NULL)
return 0;
return 1;
}
void SetMemMgr(void)
{
mmNew.GetMem=MyGetMem;
mmNew.FreeMem=MyFreeMem;
mmNew.ReallocMem=MyReallocMem;
GetMemoryManager(mmOld);
SetMemoryManager(mmNew);
}
... WinMain(.....
Application->Initialize();
SetMemMgr(); // SET NEW MEM MGR HERE......
Application->CreateForm(__classid(TForm1), &Form1);
Technical Details
Message-ID:
<3f9406e1$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,f82aceb7bb7572da,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-10-20 09:10:11 PST From: "CC" <Xcurtc@tmscorp.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Global mem functions and threading Date: Mon, 20 Oct 2003 11:02:19 -0500 Lines: 62 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: <3f9406e1$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1066665697 208.254.250.201 (20 Oct 2003 09:01:37 -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