d-mozulyov / BrainMM

Extremely fast memory manager for Delphi
http://www.sql.ru/forum/1213139/ekstremalno-bystryy-menedzher-pamyati-brainmm
MIT License
96 stars 16 forks source link

runtime error on second programm instance #6

Open mjmucha opened 7 years ago

mjmucha commented 7 years ago

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.

d-mozulyov commented 7 years ago

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)

mjmucha commented 7 years ago

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.

d-mozulyov commented 7 years ago

Great to hear it :)

vfbler commented 7 years ago

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

hippowar commented 6 years ago

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

d-mozulyov commented 6 years ago

Hi!

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

chmichael commented 6 years ago

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

mjmucha commented 6 years ago

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

chmichael commented 6 years ago

Hello, Any chance this summer ? :)

d-mozulyov commented 6 years ago

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!

jaclas commented 6 years ago

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

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

chmichael commented 6 years ago

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.

d-mozulyov commented 6 years ago

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!

chmichael commented 6 years ago

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

d-mozulyov commented 6 years ago

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

vintagedave commented 6 years ago

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

d-mozulyov commented 6 years ago

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

kazalex commented 6 years ago

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
nyburner commented 6 years ago

Ptr not initialized before loop.

On Wed, Jun 13, 2018, 05:00 kazalex, notifications@github.com 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 .

kazalex commented 6 years ago

Ptr not initialized before loop.

Global variables always initialized by zero/nil etc.

d-mozulyov commented 6 years ago

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>;
dnwerner commented 3 years ago

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.