Coder's Guild Mailing List

PByte

Posted by Renke de Boer on 2000-06-05

Look at this:

Type a = record
     data: pbyte; (pointer to a byte)
     end;
     b = ^a;       (pointer to a)

var c : b;

begin
GetMem(c,5*SizeOf(a));   (SizeOf(a) is 4 bytes)
end;

It allocates more memory than the size of the record a.
I think it allocates 5 pointers like data. Thus 5 x data(pbyte).

Is this the good/official way? I think it's uncommon. I never seen this 
before. Why don't use a pointer in stead of a pbyte?


And this one:

Type pbyte = ^byte
     spritetype = record
     spritedata: pbyte;
     end;

procedure createsprite(data:pbyte;var sprite:spritetype);
begin
getmem(sprite.spritedata,x*y);
move(data^,sprite.spritedata^,x*y);
end;

It copies the contents of data to sprite.spritedata.
Is this the official way? It allocates for a pbyte more memory than one 
byte. Normal when it is read it returns a byte. I think it's better to use a 
pointer instead of a pbyte. Or isn't?

Or is there a special meaning for using a pbyte in stead of a (normal) 
pointer?
I hope someone can help me.
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com