Solved

large ARRAY-variable (Stack Overflow)

Posted on 2004-04-05
7
643 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 130 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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
 

Expert Comment

by:TomGrills
ID: 10801104
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 276
Delphi XE10 Round Image 2 129
oracle global variables 4 69
Breakpoint doesn't stop in my variable 3 28
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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