Solved

access violation at address in module ntdll.dll

Posted on 2014-04-03
15
2,561 Views
Last Modified: 2014-04-08
Hi Experts, I got one of these errors during a run of my app while processing a large datafile. Oddly enough, during a similar run with same file 10 minutes prior, this error did not occur and my app ran clean. I rebooted after this error and ran my app again on this same large datafile (5 or 6 times) and the error did not happen again. Should I be concerned about my app, or does it look like just some kind of OS glitch that was cleared up upon reboot?

Also, regarding these "access violation" errors (and similar errors causing crashes), would there happen to be some sort of magical Delphi component that I can add to my project which would output some sort of log file indicating where in my app (source code line number?) the crash occurred?

Thanks
    Shawn
0
Comment
Question by:shawn857
  • 7
  • 5
  • 3
15 Comments
 
LVL 36

Accepted Solution

by:
Geert Gruwez earned 300 total points
Comment Utility
magic ?
try madExcept from madshi ...  http://www.madshi.net/
or eurekalog ...

both have the capability of producing a stack trace and mailing a bug report when an access violcation happens

after installing madExcept recompile your project
> check next to options in the delphi IDE project  menu for the madexcept options
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
Comment Utility
Seem that you have a memory leak - when os is run long enough and a resources are little come out - maybe this error occurre. Maybe possible collision with some other process.

There is EurekaLog:
http://edn.embarcadero.com/article/39115
http://delphi.about.com/od/productreviews/ss/eurekalog.htm
https://www.eurekalog.com/

or madExcept:
http://madshi.net/

... tools/components/unit to help you out.
Personally, think that madExcept is a very good option - and do exactly you want.

How do you access/process large file? Did you access exclusive to other process?

---------

EDITED: seem that I was little late....
0
 

Author Comment

by:shawn857
Comment Utility
Thanks guys! I already use FastMM4 in my project - would using madExcept as well be okay, or would they "compete" with each other?

Sinisa: I read and process my large data file exclusively. No other process accesses the datafile.

Thanks!
    Shawn
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
Comment Utility
You never know who want to access... (virus, anti-virus, fbi... :-)
FastMM is good for memory leak + speed string manipulation, but for exceptions is madExcept. Few times I have problem with FastMM and externall dlls. (both needs FastMM) - use latest version.
0
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
are you loading the complete (very large) file ?
how ? in a stringlist ?
0
 

Author Comment

by:shawn857
Comment Utility
Geert: To read in the very large file, I just read one record at a time into a normal string variable, process that record, then read another record in. No stringlist. Very plain vanilla.

Guys: I am trying madExcept and I think it will be what I need to catch exceptions... but when I have it enabled, it seems to slow down quite a lot the process of reading my large datafile. Is this normal?

Thanks
   Shawn
0
 

Author Comment

by:shawn857
Comment Utility
Geert - update to what I wrote earlier. After more testing, it seems my program runs about 10% slower when madExcept is enabled. Not the end of the world, but strange that it slows it down at all.

Thanks
   Shawn
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
i never leave it on for long. just initially  to find bugs and av

i don't really have mission critical software
and if something slow, the process gets chopped up and spread across app servers

whenever i need to process large amounts of data
> check if the writer of the large file can create a secondary file with only the items i'm interested in
> check if i can extract the data i need myself

fwiw, there is no point in analyzing a log file
the logfile was written based on processed data > read the processed data instead
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
Comment Utility
Maybe you can run faster. How you read file? With Readln or you use allocated memory as buffer? Second one is a right direction.
0
 

Author Comment

by:shawn857
Comment Utility
Sinisa - I read a file of variable-length text lines (ie. a CSV file), so I think I have to use Readln, no?

Shawn
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
Comment Utility
Not necessarily. Read buffer (let say 10k), parse csv and do the job, when you analyze all buffer read another portion and so on until all file is readed. When you detect CRLF chars - you have one record (calculated form previous CRLF).
0
 
LVL 25

Assisted Solution

by:Sinisa Vuk
Sinisa Vuk earned 200 total points
Comment Utility
I made (not so simple to understand) example (but working :-) using buffered reading:

function TForm1.AnalzyeBuffer(const pText: PChar; const iBufSz: Cardinal;
  var iAnalyzed: Cardinal): Boolean;
const
  DELIMIT_CHAR = ';';
var
  {s,} sFields: String;
  pFieldStart, p: PChar;
  i, iLineLen: Cardinal;
begin
  Result := True; //keep going on
  iAnalyzed := 0;

  if iBufSz > 0  then
  begin
    sFields := '';
    iLineLen := 0;
    pFieldStart := nil; //first

    for i := 0 to (iBufSz-1) do
    begin
      p := PChar(Cardinal(pText) + i);
      Inc(iLineLen);

      //find next delimiter char
      if (p^ = DELIMIT_CHAR) or (p^ = #0) then //complete field? (delimeter or zero terminated from last time)
      begin
        //trick - replace delimt char with 0 - to make zero-terminated string
        p^ := #0;

        //get complete string value/field
        sFields := sFields + ' * ' + String(pFieldStart);
        pFieldStart := nil; //set for next
      end
      else if (p^ = #13) or (p^ = #10) then //CR / LF - is las field delimiter also
      begin
        //trick - replace delimt char with 0 - to make zero-terminated string
        p^ := #0;

        if pFieldStart<>nil then
        begin
          //get complete string value/field
          sFields := sFields + ' * ' + String(pFieldStart); //for debug purpose I concatenate field values
          //field can be storen in record/structure too
          pFieldStart := nil; //set for next
        end;

        //line finished
        if Length(sFields) > 0 then
        begin
          //sFields contains all fields ..... do additional processing here...
          //
          sFields := ''; //after CR next LF will not trigger - (eat LF)
        end;

        Inc(iAnalyzed, iLineLen); //calc whole line
        iLineLen := 0;  //reset line
      end
      else //just eat chars
      begin
        if pFieldStart = nil then //set new start
          pFieldStart := p;
      end;
    end;
  end;
end;

procedure TForm1.RunJob(iFileHandle: Integer);
const
  BUFSZ = 10000; //whole buffer size
var
  pText, pStartBuff: PChar;
  bGoOn: Boolean;
  iReaded, iRemainFromLastRead, iAnalyzed: Cardinal;
begin
  //allocate buffer
  GetMem(pText, BUFSZ);
  try
    GetMem(pStartBuff, BUFSZ);
    try
      ZeroMemory(pText, BUFSZ);
      iRemainFromLastRead := 0;
      repeat
        //read file and fill buffer not overriding old (remaining) text
        iReaded := FileRead(iFileHandle, PChar(Cardinal(pText)+iRemainFromLastRead)^, BUFSZ-iRemainFromLastRead);
        if iReaded > 0 then //readed buffer?
        begin
          Inc(iReaded, iRemainFromLastRead);
          bGoOn := AnalzyeBuffer(pText, iReaded, iAnalyzed);

          if not bGoOn then Break;

          iRemainFromLastRead := iReaded - iAnalyzed; //remain?
          if iRemainFromLastRead>0 then //shift remain part in memory to start position - and keep reading from that one
          begin
            CopyMemory(pStartBuff, PChar(Cardinal(pText)+iAnalyzed), iRemainFromLastRead); //temp buffer
            CopyMemory(pText, pStartBuff, iRemainFromLastRead); //working buffer
          end;
        end
        else
        begin
          if iRemainFromLastRead > 0 then //last line without CRLF?
          begin
            AnalzyeBuffer(pText, iRemainFromLastRead, iAnalyzed);
          end;
        end;
      until iReaded = 0;
    finally
      FreeMem(pStartBuff);
    end;
  finally
    FreeMem(pText);
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  sFile: String;
  iFileHandle: Integer;
begin
  sFile:='...';

  iFileHandle := FileOpen(sFile, fmOpenRead);
  if iFileHandle>=0 then
  begin
    try
      RunJob(iFileHandle);
    finally
      FileClose(iFileHandle);
    end;
  end;

  ShowMessage('end');
end;

Open in new window


This is partly answer to your another EE question.

Look for coments in code.
0
 

Author Comment

by:shawn857
Comment Utility
Thank you for that example code Sinisa, I'm going to try to play around with it.

Right now in my parsing engine, the bottleneck appears to be string manipulating and concatenating... not so much the File I/O of reading and writing.

Shawn
0
 

Author Comment

by:shawn857
Comment Utility
Guys, I think that this question and another I'm asking ("Faster string concatenation") has evolved away from the initial question I asked and have started to "overlap". As I just mentioned in that other question, when what I really should be doing is finding the fastest method to parse a CSV file and stop trying to split hairs like looking for faster string manipulation routines. I shall open a new question addressing just that and award points and wrap up this one (madExcept and EurekaLog were two very good answers to the original spirit of this question).

Thanks
    Shawn
0
 

Author Closing Comment

by:shawn857
Comment Utility
Thank you Gentlemen!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now