Recent

Author Topic: Free Pascal memory model  (Read 13462 times)

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Free Pascal memory model
« on: February 13, 2010, 08:12:34 am »
I've searched on FPC documentation about memory model, I found only details about Heap.
I want to know more about:

1. Data segment
2. Code Segment
3. Stack segment

1. Does FPC generates only 4 memory segments (in addition to heap)?
2. Does code segment, data segment, stack segments are always have a fixed size starting from the load of application in memory?

thanks


DirkS

  • Sr. Member
  • ****
  • Posts: 251
Re: Free Pascal memory model
« Reply #1 on: February 13, 2010, 10:45:19 am »
There is information about this in the FP Programmer's Guide: http://lazarus-ccr.sourceforge.net/fpcdoc/prog/prog.html.
See chapter 8 and appendix H.


motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Re: Free Pascal memory model
« Reply #2 on: February 14, 2010, 08:59:12 am »
Thanks DirkS
I already read Memory model in prog.pdf document, I found only information about heap.
About Appendix H, the stack, this is really useful, but they mentioned that stack is not limited, does this mean stack is sharing the space with heap? I mean is it allocated dynamically?

also I'm still missing information about code and data segment.
Is there a data segment? is global variables stored in heap too?

Thanks

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Free Pascal memory model
« Reply #3 on: February 14, 2010, 12:55:59 pm »
I already read Memory model in prog.pdf document, I found only information about heap.
About Appendix H, the stack, this is really useful, but they mentioned that stack is not limited, does this mean stack is sharing the space with heap? I mean is it allocated dynamically?

also I'm still missing information about code and data segment.
Is there a data segment? is global variables stored in heap too?

FPC has a protected mode model. Logically it has probably 3 segments:

- stack
- data divided into
    - (heap+vars)
    - bss (initialized data)
- code

How to map these to whatever concepts the underlying system provides varies.  But FPC doesn't care, as long as cs=code ss=stack and ds=es=data.

Some FPC targets have fixed stacks, some have dynamic ones. FPC itself provides stack depth checking, though not on all targets.

How memory is allocated for data is pretty much abstracted by the heapmanager. As long as you have a way to map (and optionally release) blocks of data it is fine.

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Re: Free Pascal memory model
« Reply #4 on: February 14, 2010, 02:32:05 pm »
Thanks
but what did you mean by heap+Vars, did you mean global variables? and what is bss? is it like initialized constants?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Free Pascal memory model
« Reply #5 on: February 14, 2010, 03:53:04 pm »
Thanks
but what did you mean by heap+Vars, did you mean global variables?

Yes.

Quote
and what is bss? is it like initialized constants?

Yes, that is the normal unix name for that segment.


Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: Free Pascal memory model
« Reply #6 on: February 15, 2010, 10:24:57 am »
and what is bss? is it like initialized constants?
Yes, that is the normal unix name for that segment.

BSS only contains global variables.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Free Pascal memory model
« Reply #7 on: February 15, 2010, 12:01:50 pm »
and what is bss? is it like initialized constants?
Yes, that is the normal unix name for that segment.

BSS only contains global variables.

Aargh, my bad.  BSS+ CONST= DATA roughly, with CONST having the initialized variables and other structures data, and BSS being the "volatile" part.

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Re: Free Pascal memory model
« Reply #8 on: February 16, 2010, 01:23:57 pm »
I've found a simple and good document about memory :
http://www.utdallas.edu/~rxc064000/memory.pdf

 

TinyPortal © 2005-2018