Schlagwort-Archive: exception

Problems with stack size/recursion in ISAPI DLL

In my actual ISAPI project I have a recursive function which in some cases is called about 300 times. In a normal EXE project it works. But in an ISAPI DLL it doesn’t. It raises an AV like this: „stack overflow at 0x77c3805a“

After some searching I found the explanation: „the maximum stack size of a thread that is created in a native IIS process is 256 KB“ The stack size of a normal EXE program is 1 MB. There is also no difference between 32bit and 64bit.

Here are some more information which helped me:
http://stackoverflow.com/questions/15883656/is-it-possible-to-change-the-default-thread-stacksize-for-a-dll-not-under-your-c
http://joel.inpointform.net/software-development/explanation-of-stack-heap-and-recursion-causing-stack-overflow/

Here is some example code:

procedure DoIt;

  procedure Recursion(const Step: Double);
  var
    aFormatSettings: TFormatSettings;
    aString: string;
    aNewStep: Double;
  begin
    //In my real project I got the AV during TFormatSettings.Create so I have made a demo with TFormatSettings.Create
    aFormatSettings := TFormatSettings.Create;
    aFormatSettings.DecimalSeparator := '.';
    aString := FloatToStr(Step, aFormatSettings);
    aNewStep := StrToFloat(aString, aFormatSettings);
    aNewStep := aNewStep + 1;
    //in an ISAPI the AV raises by < 2000 steps
    //in an EXE the AV raises by < 200000 steps
    if Step < 2000 then
      Recursion(aNewStep);
  end;

begin
  Recursion(1);
end;

How to exception logging at runtime

For exception logging You can use the TJvDebugHandler component from the JVCL. Just drop the component on the main form, set the LogFileName to a writable filename (do not use ExtractFilePath(Application.ExeName) + ‚\MyLog.txt‘) and enable logging by setting the LogToFile property to true. If You want a detailed log file / stack trace You have to insert the following lines at the beginning of Your dpr file.

// JCL_DEBUG_EXPERT_GENERATEJDBG ON
// JCL_DEBUG_EXPERT_INSERTJDBG ON
// JCL_DEBUG_EXPERT_DELETEMAPFILE ON

Yes, the lines are comments. Weiterlesen