Solved

large ARRAY-variable (Stack Overflow)

Posted on 2004-04-05
7
646 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

765 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