Shop OBEX P1 Docs P2 Docs Learn Events
memory allocation — Parallax Forums

memory allocation

CannibalRoboticsCannibalRobotics Posts: 535
edited 2011-07-18 09:43 in Propeller 1
So if one has a set of variables defined...
VAR
long     Stack[100]
long     Buffer[16]
Byte    B1
Byte    B2
Byte    B3
Byte    B4

Then compares the results of @Stack and @B4, the result should be (4*100) + (4*16) + 4 = 468, right?
OR put another way, is VARiable memory allocated contiguously.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-07-15 12:42
    Nope. LONGs are allocated first, then WORDs, then BYTEs no matter what order you declare them in. The purpose for the is to avoid "holes" when a WORD follows a BYTE or when a LONG follows a WORD or BYTE. If you want explicit control of memory order, you'll have to use a DAT section where things are allocated exactly as written (except for the "holes").
  • localrogerlocalroger Posts: 3,452
    edited 2011-07-15 12:43
    Longs, words, and bytes are grouped together according to type in that order before being allocated. Within each type, allocation is in the order Spin finds them in the VAR block.
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2011-07-18 06:50
    Will they always be contiguous within their 'type' block?
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2011-07-18 07:14
    @ Mike Green,
    (except for the "holes")

    "holes" ?

    Thanks
    Jim-
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2011-07-18 07:52
    I'm thinking now about the follow-on question for this - which I could figure out easily enough but,
    Are the allocations made for all objects LONGs, then WORDs then BYTEs or is it done in that order for each object.
    J-
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-07-18 09:28
    The VAR section is sorted by LONGs, WORDS and BYTEs independent of the other objects. The DAT section stays in the order that the variables are defined. The holes occur when a WORD or LONG variable is defined and the current memory address is not a multiple of 2 or 4 respectively. The following example will create holes. I believe the holes are filled in with zeros.
    dat
      long 123
      word 45
      long 67 ' A two-byte hole is created between this long and the previous word
      byte 8
      word 9 ' A one-byte hole is created between this word and the previous byte
    
  • localrogerlocalroger Posts: 3,452
    edited 2011-07-18 09:43
    Are the allocations made for all objects LONGs, then WORDs then BYTEs or is it done in that order for each object.

    It's done separately for each object.
Sign In or Register to comment.