Solved

large ARRAY-variable (Stack Overflow)

Posted on 2004-04-05
7
659 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

615 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