According to skye:
var gBuffer"^mode13VideoBuffer;
You mean: gBuffer: ^mode13VideoBuffer;-).
[...] All my graphic functions draw to this buffer. To get it to the screen I have a procedre that calls an external C function: procedure gUpdate; begin screenblit( gBuffer); end;
How is this C function declared in the Pascal program? As "Procedure ScreenBlit ( gBuffer: Pointer ); C;"? Then it should work.
[...] This only crashes when I pass it a pointer from my unit. I can do the exact same allocation from the main program file and it will work OK.
This I don't understand. You mean that you are using a statically allocated video buffer in the Pascal program and passing a pointer to it to the C program? The following should work:
Program Whatever;
Type mode13VideoBuffer = array [ 1 .. 320 * 200 ] of Byte; mode13VideoBufferPtr = ^mode13VideoBuffer;
Var gBuffer: mode13VideoBuffer; (* NOT a pointer to it *)
Procedure ScreenBlit ( Buffer: mode13VideoBufferPtr ); C;
begin ScreenBlit ( @gBuffer ); end.
Am I getting confused on how pointers work in C and how they work in Pascal (I thought that they were pretty much the same except for type checking
Yes, they are.
and "true" dynamic allocation)?
What's that? What's "false" with `New' and `GetMem'? :-)
Hope this helps,
Peter
Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201] maintainer GNU Pascal [970420] - http://home.pages.de/~gnu-pascal/ [970125]
At 03:56 PM 4/26/97 +0200, you wrote:
According to skye:
var gBuffer"^mode13VideoBuffer;
You mean: gBuffer: ^mode13VideoBuffer;-).
yah,... right <grin>
This I don't understand. You mean that you are using a statically allocated video buffer in the Pascal program and passing a pointer to it to the C program? The following should work:
Program Whatever; Type mode13VideoBuffer = array [ 1 .. 320 * 200 ] of Byte; mode13VideoBufferPtr = ^mode13VideoBuffer; Var gBuffer: mode13VideoBuffer; (* NOT a pointer to it *) Procedure ScreenBlit ( Buffer: mode13VideoBufferPtr ); C; begin ScreenBlit ( @gBuffer ); end.
Yes, I can get that to work but what still fails is when gBuffer is allocated using new(): var gBuffer:^mode13VideoBuffer; (* IS a pointer *) ....... new(gBuffer); ....... ScreenBlit( gBuffer); (* crashes in the movedata() from the std C lib *) ....... dispose(gBuffer); ....... end.
Now I'm not too sure how memory allocation works under pascal. Is this right? I don't have many examples to got from and they all work something like this. would this be the same as this in C:
char* gBuffer; gBuffer = malloc(320*200); free(gBuffer);
What's "false" with `New' and `GetMem'? :-)
now I haven't seen GetMem before. The examples I'm using just use the method i've shown above. Does GetMem work like malloc() where I can specify the amount at runtime? (this would be nice). Also, isn't there a limit to the amount of static variable memory I can use (DS)? I don't want to have to fidle with my compiler options to increase it. If I have a static array that is 64k there is potental for probles way down the road, esp. if I have other large static structres.
Sorry about the basic Pascal questions. It is strange switching from C/C++ to Pascal without documentation. I keep trying to do something one way and find out after much frustration that is done another in Pascal. I have only a few Pascal DOCS I have found online and they all use TP. Are there any using GPC?
Hope this helps,
Peter
Very much, thanks.
-Skye