Your Rank: 92
Hi, thank you for your answer.
As far as I can see, the FastMM memory manager fills unallocated memory with non-zero bytes. The generated code access this unallocated memory during cleanup. This works with the default memory manager, because the code test for nil pointer. But in my opinion no code should access any unallocated code at any time.
I am using FastMM in oder to catch and find memory related problems. Would compiler generated code that results in heap corruption with FastMM in "debug mode" but not with the build in memory manager be categorized as an compiler error?
The code that generates heap corruption with FastMM are (simpler code might do the trick also):
procedure Test2( AInput: TBytes); begin end; function Test( ACommand: Byte; const AHeader: TBytes):TBytes; begin Result:=AHeader; Test2([ACommand]+Result); end; procedure Main; begin Test($42,[$42,42]); end.
The heap corruption will cause out of memory exceptions later on in the program, making it exceptionally hard to find the root cause.
Changeing the function test to the following solves the problem:
function Test( ACommand: Byte; const AHeader: TBytes):TBytes; var Input: TBytes; begin Result:=AHeader; Input:=[ACommand]+Result; Test2(Input); end;
It turns out that the code Test2([ACommand]+Result) does the follwing:
- Creates a dynamic array with one byte.
- Concatenates this array with Result, In this process a new array is created ant he array created in step 1 is disposed.
- The problem now is that the cleanup code for the function Test disposes the array created in step 1 one more time. This works fine if the memory is initialized to zero values, as it will be with the normal memory manager. But with FastMM in debug mode, memory are filled with nonzero values when freed, and heap corruption occurs.
By looking at the WebBrowser control I figured out a solution. Apparently you need to use the TJNativeLayout class:
I have a java library which implements a Andorid view (the Java class inherits from LinearLayout). I would like to use this view in my Delphi FireMonkey application. I have access to the classes in the Java library using the Java bridge, but I cannot figure out how I can display such a view in my FireMonkey application.
My code looks something like this:
View:=MainActivity.GetViewGroup;JavaView:=TJJavaView.JavaClass.init(SharedActivityContext);FillParent:=-1;JavaView.SetLayoutParams(TJFrameLayout_LayoutParams.JavaClass.init(FillParent,FillParent));View.AddView(JavaView);If I call JavaView.GetWidth and JavaView.GetHeight I can see that the view is aligning to the full client area of the app. Can anyone tell me how I can get this view visible?
About meI am a software developer from Denmark. I have been using Delphi since the first release, and before that Turbo Pascal.