BrainMM icon indicating copy to clipboard operation
BrainMM copied to clipboard

runtime error on second programm instance

Open mjmucha opened this issue 7 years ago • 22 comments

When starting a second instance of the same program with BrainMM i get a access violation on the line 10523 (master).

  if (BrainMMRegistered.BrainMM.Options.FreePacalCompiler <> {$ifdef FPC}True{$else}False{$endif}) then
    begin
      BrainMMFreeMemOriginal := MemoryManager.Standard.FreeMem;
      MemoryManager.Standard.FreeMem := BrainMMFreeMemInverter;
    end;

It seems that MapAddress := MapViewOfFile(BrainMMRegisteredHandle, FILE_MAP_READ, 0, 0, 0); isn't working as expected (line 10470). The fields of BrainMMRegistered are all nil.

This bug occurs with Debug Win 32 Delphi 10.2 Toyko.

mjmucha avatar Jul 27 '17 04:07 mjmucha

Thanks! Could you attach a test project please to repeat the bug?

Now the BrainMM is unstable, a development will be continued this autumn (may be winter)

d-mozulyov avatar Jul 27 '17 15:07 d-mozulyov

Sure! BrainMM Test.zip

Nice to hear! We are using it now for a 2D OpenGL game which is in development sine ~2012 and got serious performance boosts from it.

mjmucha avatar Jul 27 '17 22:07 mjmucha

Great to hear it :)

d-mozulyov avatar Jul 28 '17 05:07 d-mozulyov

Buffer: array[0..SizeOf(BRAINMM_MARKER) + 8] of WideChar; -> Buffer: array[0..Length(BRAINMM_MARKER) + 8] of WideChar;

vfbler avatar Aug 14 '17 14:08 vfbler

Wow! it's already reported... i just did like this. FillChar(Buffer, SizeOf(Buffer), #1);

hippowar avatar Mar 19 '18 05:03 hippowar

Hi!

Unfortunately, the library development was temporarily suspended. Hope it will be continued this summer!

d-mozulyov avatar Mar 20 '18 19:03 d-mozulyov

Can't wait, it seems you have made awesome job and a couple bugs stops people from using it. :)

chmichael avatar Mar 25 '18 02:03 chmichael

We are still using it and we also can't wait for updates! :)

mjmucha avatar Mar 25 '18 05:03 mjmucha

Hello, Any chance this summer ? :)

chmichael avatar Jun 05 '18 15:06 chmichael

Hello, guys! I want to say thank you for your anticipation and patience! However, at the moment there are more priority tasks. The next possible release date is winter. Or if someone succeeds in attracting donations/investments of $5000-$10000 - the development will continue immediately. Thank you again for your attention to the project!

d-mozulyov avatar Jun 05 '18 18:06 d-mozulyov

Well... I guess so this thread can be now closed, forever ;-)

and please try https://github.com/maximmasiutin/FastMM4-AVX

jaclas avatar Jun 05 '18 21:06 jaclas

Hello Mozulyov, Well it's unlikely anyone will donate such amount for project with serious bugs too. You can setup a "donation" somewhere and everyone who wants will donate.

Another solution is to make it shareware which you definitely make money there especially if it's better than FastMM.

I would glady donate 20$ if the service bug is fixed so i can use it.

chmichael avatar Jun 06 '18 19:06 chmichael

jaclas, Thank you for the good link. But FastMM4-AVX still works through locks. This means that on multithreaded applications, BrainMM or even WindowsMM will be much faster. Here is a project-benchmark, you can check the performance yourself.

Advantage of the library in accelerated memory re-allocation operations. But in fact re-allocation of memory is a rare operation. In algorithms where re-allocation is required, the concept of "capacity" is used, when the memory is periodically allocated more than necessary to fill it in the future. Such an approach, for example, is used in containers TList<> and ТDictionary<>. In TMemoryStream/TByteStream. This can be useful for dynamic arrays and strings. But since Delphi 10.1 (Berlin) re-allocation of dynamic arrays is only through the creation of new ones. And strings in the areas critical for the speed are filled through the TStringBuilder (also through capacity).

But the link is really useful. Many thanks!

d-mozulyov avatar Jun 07 '18 06:06 d-mozulyov

I did "advertise" the project and your needs on Google+ Delphi Developers, i hope i turns well and you can continue the development.

chmichael avatar Jun 08 '18 15:06 chmichael

chmichael, oh, cool, thanks! Donate Link USD VISA 4779 6426 1574 7797 RUB VISA 4154 8120 7035 2715

d-mozulyov avatar Jun 08 '18 18:06 d-mozulyov

Dmitrij, do you have an email I can contact you on, please?

vintagedave avatar Jun 11 '18 13:06 vintagedave

vintagedave, Hi, sure! See my contacts in the unit header

d-mozulyov avatar Jun 11 '18 15:06 d-mozulyov

But since Delphi 10.1 (Berlin) re-allocation of dynamic arrays is only through the creation of new ones.

What???

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

var

 bts : TBytes;
 i   : Integer;
 ptr : Pointer;

begin

 for i := 1 to 10000000 do
  begin

   setlength(bts, i);

   if ptr <> pointer(bts) then // real new array
    begin

     writeln(i);
     ptr := pointer(bts);

    end;

  end;

 readln;

end.

Delphi 10.1:

1
5
53
149
341
725
1493
29477
95877
215989
327653
786405
1769445
3997669
9043941

kazalex avatar Jun 13 '18 11:06 kazalex

Ptr not initialized before loop.

On Wed, Jun 13, 2018, 05:00 kazalex, [email protected] wrote:

But since Delphi 10.1 (Berlin) re-allocation of dynamic arrays is only through the creation of new ones.

What???

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses System.SysUtils;

var

bts : TBytes; i : Integer; ptr : Pointer;

begin

for i := 1 to 10000000 do begin

setlength(bts, i);

if ptr <> pointer(bts) then // real new array begin

 writeln(i);
 ptr := pointer(bts);

end;

end;

readln;

end.

Delphi 10.1:

1 5 53 149 341 725 1493 29477 95877 215989 327653 786405 1769445 3997669 9043941

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/d-mozulyov/BrainMM/issues/6#issuecomment-396898611, or mute the thread https://github.com/notifications/unsubscribe-auth/AFaHHL4PXwAowRkuSVeGgJ-1zmprqwfYks5t8PDbgaJpZM4OkxL0 .

nyburner avatar Jun 13 '18 11:06 nyburner

Ptr not initialized before loop.

Global variables always initialized by zero/nil etc.

kazalex avatar Jun 13 '18 11:06 kazalex

kazalex, Thanks, I was a little wrong. But if you change the type of the variable, you will understand what I mean.

var
  bts : TArray<TBytes>;

d-mozulyov avatar Jun 13 '18 19:06 d-mozulyov

Dear @d-mozulyov ,

I just ran the change you proposed under Delphi 10.3 (using a TArray<TBytes>) and the output of the program was:

1
2
14
38
86
182
374
7370
23970
53998
81914
196602
442362
999418
2260986
5095418

This agrees with what @kazalex wrote and is conflicting with your statement (or it could have been fixed in 10.3)

But since Delphi 10.1 (Berlin) re-allocation of dynamic arrays is only through the creation of new ones.

dnwerner avatar Feb 04 '21 22:02 dnwerner