Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

large ARRAY-variable (Stack Overflow)

Posted on 2004-04-05
7
Medium Priority
?
680 Views
Last Modified: 2008-01-09
Im trying to declare a LARGE array, but i get the EStackOverflow-exception :-(
Maybe I could do this in a better way by using GETMEM and pointers, but how??

The code is following:

procedure TForm1.Button1Click(Sender: TObject);
const
  MaxY=600;
  MaxX=1600;

type
  tboardType=Array[0..MaxY] of Array[0..MaxX] of byte;

var
  cb,tb:tboardtype;

begin
  FillChar(cb,SizeOf(cb),0);
  FillChar(tb,SizeOf(tb),0);
end;
0
Comment
Question by:hutelihut
  • 4
  • 2
7 Comments
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 10756873
taken from the delphi help file

"Static array types are denoted by constructions of the form

array[indexType1, ..., indexTypen] of baseType

where each indexType is an ordinal type whose range does not exceed 2GB. "

your array exceeded 2GB
0
 

Accepted Solution

by:
TomGrills earned 520 total points
ID: 10756906
Here's one way.....

procedure TForm1.Button1Click(Sender: TObject);
const
  MaxY=600;
  MaxX=1600;

type
// First, define a pointer to the static type
  PboardType=^TBoardType;
  tboardType=Array[0..MaxY] of Array[0..MaxX] of byte;

var
  cb,tb:Pboardtype;
  testbyte:byte;
begin
  // Now you must get the memory for the arrays;
  getmem(cb,sizeof(TBoardType));
  getmem(tb,sizeof(TBoardType));

  // Always dereference your pointer when in use
  FillChar(cb^,SizeOf(cb^),0);
  FillChar(tb^,SizeOf(tb^),0);

  //  To Access values...
  Testbyte:=cb^[2][44];

  //  When finished, you have to free the pointers
  freemem(cb);
  freemem(tb);
end;
0
 

Expert Comment

by:TomGrills
ID: 10756964
Jase-Coder,

   His array is well within the 2gb limit...  it's only 600*1600 elements or 960000 bytes
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 11

Expert Comment

by:Jase-Coder
ID: 10768122
Tom: I complied a copy and it said it exceeds the 2GB limit
0
 

Author Comment

by:hutelihut
ID: 10801027
hmm... I got a little problem... Delphi comes up with a warning "Unsafe code Getmem". What does that mean??
0
 

Expert Comment

by:TomGrills
ID: 10801093
It just means that it won't be portable to .NET....  Here's the quote:

Unsafe code warnings in Delphi
Starting with Delphi 7, the compiler includes three new warnings that can help you locate code that is non-portable (i.e. it uses a deprecated language feature or type), or unsafe in the .NET Framework. In the .NET Framework, "unsafe" simply means that the code cannot be verified by the static analysis performed by the CLR when the code is loaded. The compiler can warn about the usage of unsafe types, unsafe code, and unsafe casts.

Unsafe types
  PChar, PWideChar, and PAnsiChar  
  Untyped pointers
  Untyped var and out parameters  
  File of <type>
  Real48
  Variant records (records containing overlapping fields)

Unsafe code
  Absolute variables  
  Addr(), Ptr(), Hi(), Lo(), Swap() standard procedures
  BlockRead(), and BlockWrite()
  Fail()
  GetMem(), FreeMem(), ReallocMem()
  inline assembler
  the @ operator

......


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question