Solved

Trouble with Dynamic Arrays in Delphi 2007  --  Causing illegal pointer and/or out of mem errors

Posted on 2008-06-15
4
535 Views
Last Modified: 2010-04-21
I'm rewriting an application that has worked a long time and well using static arrays but we now need to handle much larger data sets of variable size:  The app is a statistical analysis program and in the course of the analysis process I transform the data through about 50 arrays - most of type extended.

As different sets of data are loaded for processing I size the collection of dynamic arrays with a procedure that includes sets of lines like this:  (one for eacy of the many arrays)   Many of the arrays are two dim as shown below - some are single dim - but all are of varrying size depending on the data set.

    if isRaDc<>nil then  isRaDc:=nil;
    SetLength(isRaDc, cpnts, creps);                // [0..callibration_pnts, 0..callibration_reps] of Extended;
      for I := 0 to high(isRaDc) do for j := 0 to high(isRaDc[i]) do isRaDc[i,j]:=0.0;

In the above lines - if I leave out the nil statement I soon get an "out of memory" error after several runs.
If I include it - either with or without several different ways of making it conditional, I get an "illegal pointer operation error" upon the second or third run - depeding on the arrays sizing.

Should I be doing something to force garbage collection after each run - If so I have no idea how?
0
Comment
Question by:DMTrump
[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
  • 3
4 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 500 total points
ID: 21789982
I usually do this to clear my array.
SetLength(myarray, 0);
0
 

Author Comment

by:DMTrump
ID: 21790814
A good method - but subbing that for my previous nil assignment did not prevent the "illegal pointer operation" error.  I can't investigate any further tonight, but will tomorrow morning.  

Previous experimentation however, showed that the illegal pointer operation occurred not on a particular array, but after a certain approximate number of reset operations.  Can you think of other causes of illegal pointer message that I could look for in my code?

Perhaps I need to close this question (award you the points) and open a new more general one about causes of illegal pointer messages?

0
 

Author Closing Comment

by:DMTrump
ID: 31467391
A good solution to the question I asked - but it didn't solve my problem.

experimenting further I was able to determine that the problem is elsewhere in my code.  Wish me luck!
0
 

Author Comment

by:DMTrump
ID: 21799324
TheRealLoki,

Thanks again for your help - being able to determine that the problem was NOT associated with the dynamic array routines - (no one posted a "you idiot!" appraisal of my code snippet) gave me the information I needed to go looking in the other places - and I found the problem.

The take-away, for anyone else who might stumble on this is that errors may (in fact often do) show up in obscure unrelated code because your real error has set up conditions that cause a reportable error condition (I use EurekaLog) at some other point in your code.  That's a good thing to remember!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to save the image in the .cds File ClientDataSet? 1 42
Delphi, TImage, Png 2 57
collection output issue 9 96
TAction.OnAfterExecute? 2 32
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

752 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