help!! stack overflow

ok I have a problem. it has been isolated to the array I am using, a 4-D one as a matter of fact. When typed it looks like this:

dorms= array [1..4,1..2,1..20,1..2] of stuff (*the record I created*);

the first dimension pickes the dorm
the second picks the floor
the third picks the room
and the last one picks the occpiant.

is there any way to shorten this or anything, I tryed a segment with a failure and I am currently trying to use a unit, but i am having trouble. If anyone can help it would be greatly appreciated
thanks, Josh

Comments

  • : ok I have a problem. it has been isolated to the array I am using, a 4-D one as a matter of fact. When typed it looks like this:
    :
    : dorms= array [1..4,1..2,1..20,1..2] of stuff (*the record I created*);
    :
    : the first dimension pickes the dorm
    : the second picks the floor
    : the third picks the room
    : and the last one picks the occpiant.
    :
    : is there any way to shorten this or anything, I tryed a segment with a failure and I am currently trying to use a unit, but i am having trouble. If anyone can help it would be greatly appreciated
    : thanks, Josh

    Hey Josh,

    Your problem *probably* isn't this array. It's a mixture of all your variables. This array is 320*(Size of your Record) bytes large. All your variables cannot exceed 64k, so if your record contains even one string variable (size 256), it will be too large. (320*256 > 65535)
    You can take care of this in a couple of ways. The easiest would be to reduce the size of your string variables if you do have them in your record:
    [code]
    TYPE
    MyRecord = Record
    Name : String[25];
    Age : Word;
    End;

    VAR
    MyArray : Array[1..4,1..2,1..20,1..2] Of MyArray;
    [/code]

    In the above example, the names have been limited to a size of 25 characters, so instead of using 256 bytes, it only uses 26 (25+1).
    So, each record would only be 28 bytes instead of 258 bytes and the total array would be [28*320] = 8960 bytes instead of [258*320] = 82560 bytes.

    The second method would be to use an array like such:
    [code]
    TYPE
    TheArray : Array[1..2,1..20,1..2] Of MyRecord;
    ArrayPtr = ^TheArray;
    VAR
    dorms : Array [1..4] Of ArrayPtr;
    X : Byte;

    Begin
    For X := 1 to 4 Do
    New(dorms[X]);

    { Insert code Here }

    For X := 1 to 4 Do
    Dispose(dorms[X]);
    End.
    [/code]

    This would allow you to use larger arrays with less limits than just decalring them. They would have to be used slightly differently (such as dorms[1]^.[1,1,1]) but each dorms[x] could be up to 64k.

    Hope this helps you out a bit
    Phat Nat

  • : : ok I have a problem. it has been isolated to the array I am using, a 4-D one as a matter of fact. When typed it looks like this:
    : :
    : : dorms= array [1..4,1..2,1..20,1..2] of stuff (*the record I created*);
    : :
    : : the first dimension pickes the dorm
    : : the second picks the floor
    : : the third picks the room
    : : and the last one picks the occpiant.
    : :
    : : is there any way to shorten this or anything, I tryed a segment with a failure and I am currently trying to use a unit, but i am having trouble. If anyone can help it would be greatly appreciated
    : : thanks, Josh
    :
    : Hey Josh,
    :
    : Your problem *probably* isn't this array. It's a mixture of all your variables. This array is 320*(Size of your Record) bytes large. All your variables cannot exceed 64k, so if your record contains even one string variable (size 256), it will be too large. (320*256 > 65535)
    : You can take care of this in a couple of ways. The easiest would be to reduce the size of your string variables if you do have them in your record:
    : [code]
    : TYPE
    : MyRecord = Record
    : Name : String[25];
    : Age : Word;
    : End;
    :
    : VAR
    : MyArray : Array[1..4,1..2,1..20,1..2] Of MyArray;
    : [/code]
    :
    : In the above example, the names have been limited to a size of 25 characters, so instead of using 256 bytes, it only uses 26 (25+1).
    : So, each record would only be 28 bytes instead of 258 bytes and the total array would be [28*320] = 8960 bytes instead of [258*320] = 82560 bytes.
    :
    : The second method would be to use an array like such:
    : [code]
    : TYPE
    : TheArray : Array[1..2,1..20,1..2] Of MyRecord;
    : ArrayPtr = ^TheArray;
    : VAR
    : dorms : Array [1..4] Of ArrayPtr;
    : X : Byte;
    :
    : Begin
    : For X := 1 to 4 Do
    : New(dorms[X]);
    :
    : { Insert code Here }
    :
    : For X := 1 to 4 Do
    : Dispose(dorms[X]);
    : End.
    : [/code]
    :
    : This would allow you to use larger arrays with less limits than just decalring them. They would have to be used slightly differently (such as dorms[1]^.[1,1,1]) but each dorms[x] could be up to 64k.
    :
    : Hope this helps you out a bit
    : Phat Nat
    :
    :
    There is a small error in your example of using the record (dorms[1]^.[1,1,1]). The dot needs to be omitted, because dorms[x]^ isn't a record but an array, so it should read: dorms[1]^[1,1,1].
    There is a less-confusing way. That is to create a record pointer and then create an array of those pointers. Example:
    [code]
    TYPE
    MyRecord = record
    { Fields }
    end;
    PMyRecord = ^MyRecord;
    VAR
    dorms : Array [1..4,1..2,1..20,1..2] Of PMyRecord;
    X : Byte;
    [/code]
    To get a whole record, just use dorms[1,1,1,1]^.
  • : : : ok I have a problem. it has been isolated to the array I am using, a 4-D one as a matter of fact. When typed it looks like this:
    : : :
    : : : dorms= array [1..4,1..2,1..20,1..2] of stuff (*the record I created*);
    : : :
    : : : the first dimension pickes the dorm
    : : : the second picks the floor
    : : : the third picks the room
    : : : and the last one picks the occpiant.
    : : :
    : : : is there any way to shorten this or anything, I tryed a segment with a failure and I am currently trying to use a unit, but i am having trouble. If anyone can help it would be greatly appreciated
    : : : thanks, Josh
    : :
    : : Hey Josh,
    : :
    : : Your problem *probably* isn't this array. It's a mixture of all your variables. This array is 320*(Size of your Record) bytes large. All your variables cannot exceed 64k, so if your record contains even one string variable (size 256), it will be too large. (320*256 > 65535)
    : : You can take care of this in a couple of ways. The easiest would be to reduce the size of your string variables if you do have them in your record:
    : : [code]
    : : TYPE
    : : MyRecord = Record
    : : Name : String[25];
    : : Age : Word;
    : : End;
    : :
    : : VAR
    : : MyArray : Array[1..4,1..2,1..20,1..2] Of MyArray;
    : : [/code]
    : :
    : : In the above example, the names have been limited to a size of 25 characters, so instead of using 256 bytes, it only uses 26 (25+1).
    : : So, each record would only be 28 bytes instead of 258 bytes and the total array would be [28*320] = 8960 bytes instead of [258*320] = 82560 bytes.
    : :
    : : The second method would be to use an array like such:
    : : [code]
    : : TYPE
    : : TheArray : Array[1..2,1..20,1..2] Of MyRecord;
    : : ArrayPtr = ^TheArray;
    : : VAR
    : : dorms : Array [1..4] Of ArrayPtr;
    : : X : Byte;
    : :
    : : Begin
    : : For X := 1 to 4 Do
    : : New(dorms[X]);
    : :
    : : { Insert code Here }
    : :
    : : For X := 1 to 4 Do
    : : Dispose(dorms[X]);
    : : End.
    : : [/code]
    : :
    : : This would allow you to use larger arrays with less limits than just decalring them. They would have to be used slightly differently (such as dorms[1]^.[1,1,1]) but each dorms[x] could be up to 64k.
    : :
    : : Hope this helps you out a bit
    : : Phat Nat
    : :
    : :
    : There is a small error in your example of using the record (dorms[1]^.[1,1,1]). The dot needs to be omitted, because dorms[x]^ isn't a record but an array, so it should read: dorms[1]^[1,1,1].
    : There is a less-confusing way. That is to create a record pointer and then create an array of those pointers. Example:
    : [code]
    : TYPE
    : MyRecord = record
    : { Fields }
    : end;
    : PMyRecord = ^MyRecord;
    : VAR
    : dorms : Array [1..4,1..2,1..20,1..2] Of PMyRecord;
    : X : Byte;
    : [/code]
    : To get a whole record, just use dorms[1,1,1,1]^.

    Right, thanks for correcting me. When I was writing it, I was trying to remember but my mind was on my midterm :o
    The only reason I didn't do the example the way you stated above is that you end up having to decalre a whole ton of memory locators (New/GetMem). The other way you only have to declare four, although, this one would be able to handle larger records.

    Phat Nat

  • thanks for the help so far.
    i'll post the record and the rest of the stuff now.

    (*---------------------------------------------------------------*)
    names= packed array[1..15 of char;
    address= record
    zip,street,city,state:names
    end;
    stuff=record
    lives:address; (* this is the problem isn't it?*)
    gender, smoking, age, phone, name, major:names
    end;
    (*----------------------------------------------------------------*)

    that's the rest of the code.
    thanks, Josh
  • : thanks for the help so far.
    : i'll post the record and the rest of the stuff now.
    :
    : (*---------------------------------------------------------------*)
    : names= packed array[1..15 of char;
    : address= record
    : zip,street,city,state:names
    : end;
    : stuff=record
    : lives:address; (* this is the problem isn't it?*)
    : gender, smoking, age, phone, name, major:names
    : end;
    : (*----------------------------------------------------------------*)
    :
    : that's the rest of the code.
    : thanks, Josh

    well, let's count it up:

    NAMES = 15 bytes;
    ADDRESS = 15 * 4 = 60 bytes
    STUFF = 60 + (15 * 6) = 150 bytes

    so each of your record takes up 150 bytes. If you have [1..4,1..2,1..20,1..2] Then that means:
    150 * 2 * 20 * 2 * 4 = 48000 bytes
    So, by itself, your record should be okay. However, if you have more variables, then the combination is where your problem lies. BTW is this in a procedure or are they global variables?

    Phat Nat

  • All of these varibles are global. The problems started occuring after I realized that the array needed to be 4-d. it was orginally 4*20*2.
    do you think the problem could be fixed if I made it 2*20*2? because the 4 is just the dorm to enter. I could make 4 3-d arrays. is that ok?
    BTW this is my last program of the year. lol. I've been pretty good until now.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories