Solved

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

Posted on 2008-06-15
4
536 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Part One of the two-part Q&A series with MalwareTech.
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

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