Forum > General

Dynamic arrays

(1/3) > >>

tverweij:
Are dynamic arrays allocated in one continuous memory segment?
Or can a dynamic array be fragmented?

Handoko:
Because you can use FillChar to initial dynamic arrays' content:

FillChar(MyVariable,sizeof(MyVariable), #0);


--- Quote ---Fillchar fills the memory starting at X with Count bytes or characters with value equal to Value. 
--- End quote ---
Source: https://www.freepascal.org/docs-html/rtl/system/fillchar.html

it means dynamic array occupies one continuous memory segment.

tverweij:
I read http://wiki.freepascal.org/Dynamic_array again, and you are right.
Dynamic arrays must be in a continuous memory segment.

This means that I can use copyMemory to copy the contents of one dynamic array to another.

But this also raises another question:
What if the heap is so fragmented that there is no large enough continuous free memory segment is available?
Will I get an exception or will the heap be defragmented?  Or can I defragment the heap myself in such a case?

ASerge:

--- Quote from: tverweij on April 12, 2018, 05:00:42 pm ---What if the heap is so fragmented that there is no large enough continuous free memory segment is available?
Will I get an exception or will the heap be defragmented?  Or can I defragment the heap myself in such a case?

--- End quote ---
Yes, EOutOfMemory. Write your own memory manager.

tverweij:
@ASerge: I am just trying to find out how it works, so I will know what to expect.

Navigation

[0] Message Index

[#] Next page

Go to full version