Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Wolfgang Riedmann" Newsgroups: comp.lang.clipper.visual-objects Subject: Re: SetMaxDynSize VS SetMaxThreadDynSize Date: Thu, 23 Jun 2016 04:08:20 +0200 Lines: 143 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Trace: individual.net QxPNU86fyxEY1g8TtmwX5g/DtJH/QiB9Ck78O+AjK/duPgnoY= Cancel-Lock: sha1:MifVIZgMqsoUNGBN4I4+sQpvvDc= User-Agent: XanaNews/1.18.1.6 Xref: csiph.com comp.lang.clipper.visual-objects:9482 Hi Robert, this is a very interesting piece of code! Thank you very much! But hopefully I'll be able to move my largest programs over to .NET in the next 12 months, so I don't need this anymore (again: I hope!) Wolfgang Robert van der Hulst wrote: > Jim, > > SetMaxDynSize sets the size for the main thread. > And there is really no "optimal value". What you should keep in mind > is: > > - VO will use static memory for a lot of things, such as the Symbol > table, Runtime Class information etc. MemTotal() tells you how much > is allocated at a certain moment. - Whatever you allocate for > dynamic memory will be allocated twice. VO works with 2 dynamic > memory pages (one of these is active) > > > In apps that may require a lot of memory I call a method from a timer > on the shell where I am keeping track of the used and free memory. > See below. > > At startup I initialize an initial amount of memory > SetMaxDynSize(0x4000000) // Total 64 Mb per Dynamic Page = 128 Mb > total DynSize(500) // = Preallocate 500 pages of 64 Kb > > > from the timer on the shell I call this method. You may use it at > your own risk . > > METHOD CheckDynMemSize() CLASS MySHELL > LOCAL nActualSizeAllocated AS DWORD > LOCAL nActualSizeused AS DWORD > LOCAL nActualSizeMax AS DWORD > LOCAL nMaxDynAllowed AS DWORD > LOCAL nMaxPages AS DWORD > LOCAL nNewSizeInPages AS DWORD > LOCAL nNewSizeInBytes AS DWORD > LOCAL nUsed, nMax, nCheck AS DWORD > STATIC lBusy AS LOGIC > IF ! lBusy > lBusy := TRUE > // Check RegisterAxit > nUsed := Memory(MEMORY_REGISTERAXIT) > nMax := SetMaxRegisteredAxitMethods(0) > nCheck := DWORD(MulDiv(LONG(nMax), 90, 100)) > IF nUsed > nCheck // > 90% > DebOut("Approaching RegisterAxit limit, COLLECTFORCED") > Sleep(2000) > CollectForced() > nUsed := Memory(MEMORY_REGISTERAXIT) > IF nUsed > nCheck > SetMaxRegisteredAxitMethods(DWORD(nMax * 1.5)) // 50% > more ENDIF > ENDIF > // Check RegisterKid > nUsed := Memory(MEMORY_REGISTERKID) > nMax := SetMaxRegisteredKids(0) > nCheck := DWORD(MulDiv(LONG(nMax), 90, 100)) > IF nUsed > nCheck // > 90% > DebOut("Approaching RegisterKid limit, COLLECTFORCED") > Sleep(2000) > CollectForced() > nUsed := Memory(MEMORY_REGISTERKID) > IF nUsed > nCheck > SetMaxRegisteredKids(DWORD(nMax * 1.5)) // 50% more > ENDIF > ENDIF > // Check KidStackSize > nUsed := Memory(MEMORY_STACKKID) > nMax := SetKidStackSize(0) > nCheck := DWORD(MulDiv(LONG(nMax), 90, 100)) > IF nUsed > nCheck // > 90% > DebOut("Approaching KidStack limit, COLLECTFORCED") > Sleep(2000) > CollectForced() > nUsed := Memory(MEMORY_STACKKID) > IF nUsed > nCheck > SetKidStackSize(DWORD(nMax * 1.5)) // 50% more > ENDIF > ENDIF > > nMaxDynAllowed := 1024*1024*128 > nMaxPages := nMaxDynAllowed /0x10000 > nActualSizeAllocated := DynInfoSize() * 0x10000 > // DyInfoSize returns the number of 64Kb pages > nActualSizeused := DynInfoUsed() > nActualSizeMax := SetMaxDynSize(0) > // When we have used 80 % or more of the allocated memory, > // then it is time to allocate some more pages > IF nActualSizeused > nActualSizeAllocated * 0.80 > CollectForced() > nActualSizeused := DynInfoUsed() > > IF nActualSizeused > nActualSizeAllocated * 0.80 > nNewSizeInPages := DynInfoSize() +25 > nNewSizeInBytes := nNewSizeInPages * 0x10000 > // Make sure that we do not allocate more then the > DynInfoMax. // If we reach that, then we need to set > the max to a higher number IF nNewSizeInBytes >= > nActualSizeMax IF nNewSizeInPages >= nMaxPages > // Allocate some extra memory just to be sure > SetMaxDynSize(nMaxDynAllowed) > ELSE > // Allocate some extra memory just to be sure > SetMaxDynSize(nNewSizeInBytes) > DynSize(nNewSizeInPages-1) > ENDIF > ELSE > DynSize(nNewSizeInPages) > ENDIF > > ENDIF > ENDIF > lBusy := FALSE > ENDIF > RETURN NIL > > > > Robert > > > I know the default for the SetMaxDynSize() and > > SetMaxThreadDynSize() is 16MB. > > > > The help file says about SetMaxThreadDynSize() that it is used a NEW > > thread, what about the running app? > > > > Is this redundant and SetMaxDynSize() is what is only needed if I > > am not using threads ? > > > > Jim --