* * *

Author Topic: Pre-reserving Memory as Private Heap  (Read 948 times)

diogenes

  • New member
  • *
  • Posts: 43
    • http://members.chello.at/diogenes
Pre-reserving Memory as Private Heap
« on: April 02, 2018, 09:36:37 am »
Is there a way to pre-reserve a memory block? I mean, I'm going to fetch 512 MiB of memory as a private heap, use it until it's full, and then the application will access the common heap. Is that possible? And if so, how?

taazz

  • Hero Member
  • *****
  • Posts: 5257
Re: Pre-reserving Memory as Private Heap
« Reply #1 on: April 02, 2018, 10:09:10 am »
the default memory manager already does that for you (not in 512MB range)  but if you need to you can write your own memory manager and replace the existing one. you simply replace a couple of procedure pointers at runtime with your own procedures and you are free to do what ever you like.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 6568
Re: Pre-reserving Memory as Private Heap
« Reply #2 on: April 02, 2018, 11:26:38 am »
Is there a way to pre-reserve a memory block? I mean, I'm going to fetch 512 MiB of memory as a private heap, use it until it's full, and then the application will access the common heap. Is that possible? And if so, how?
Yes there is: your classes need to override Tobject.NewInstance / TObject.FreeInstance
https://www.freepascal.org/docs-html/rtl/system/tobject.newinstance.html

If you know the size, you can pool memory that way.... (not noobs, but experienced programmers).

And taazz: there is no limit on that.....except virtual available memory.

It can also be much faster in certain scenario's.
« Last Edit: April 02, 2018, 11:31:00 am by Thaddy »
Ada's daddy wrote this:"Fools are my theme, let satire be my song."

taazz

  • Hero Member
  • *****
  • Posts: 5257
Re: Pre-reserving Memory as Private Heap
« Reply #3 on: April 02, 2018, 11:48:34 am »
Is there a way to pre-reserve a memory block? I mean, I'm going to fetch 512 MiB of memory as a private heap, use it until it's full, and then the application will access the common heap. Is that possible? And if so, how?
Yes there is: your classes need to override Tobject.NewInstance / TObject.FreeInstance
https://www.freepascal.org/docs-html/rtl/system/tobject.newinstance.html

If you know the size, you can pool memory that way.... (not noobs, but experienced programmers).

And taazz: there is no limit on that.....except virtual available memory.

It can also be much faster in certain scenario's.
I never claimed there is a limit I only said the existing manager does not cache memory on 512MB increments.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 6568
Re: Pre-reserving Memory as Private Heap
« Reply #4 on: April 02, 2018, 11:52:42 am »
I never claimed there is a limit I only said the existing manager does not cache memory on 512MB increments.
The default manager? Yes except for instance on Windows it will do virtual paging (4096).
FPC has more memory managers as standard. Like cmem, boehm...
Anyway: if you do what I say (unlike my wife) then it works.  8-) 8-)
« Last Edit: April 02, 2018, 11:55:33 am by Thaddy »
Ada's daddy wrote this:"Fools are my theme, let satire be my song."

jamie

  • Hero Member
  • *****
  • Posts: 788
Re: Pre-reserving Memory as Private Heap
« Reply #5 on: April 03, 2018, 12:57:35 am »
oh You have one of those too, Thaddy!

 :D

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus