[Lazarus] Copy buffer of PWord to TMemoryStream
Leonardo M. Ramé
l.rame at griensu.com
Sun Mar 24 19:30:48 CET 2013
On 2013-03-24 19:21:49 +0100, Sven Barth wrote:
> On 24.03.2013 19:19, Joao Morais wrote:
> >2013/3/24 Leonardo M. Ramé <l.rame at griensu.com>:
> >>Hi, I'm copying a buffer of PWord to a TMemoryStream using this code:
> >>
> >>lTmpBuff := lBuffer;
> >>I := 0;
> >>while I < lBufSize do
> >>begin
> >> lStream.Write(lTmpBuff^, SizeOf(PWord));
> >> inc(lTmpBuff, 1);
> >> inc(I, 1);
> >
> >What about:
> >
> > inc(lTmpBuff, SizeOf(PWord));
> > inc(I, SizeOf(PWord));
>
> If lTmpBuff is declared as PWord then "Inc" already increases in
> multiplies of "SizeOf(PWord)".
> Regarding lBufSize it will be important to know whether the C code
> returns the size in elements or in byte.
>
Heres the interface of the library:
myfunction(void * &buffer, unsigned long& bufSize)
{
bufsize = interdata->getcount() * sizeof(uint16);
buffer = new uint16[bufSize];
// interdata is an object containing image data
memcpy((void *)buffer, interdata->getData(), interdata->getCount());
}
So, I'm using this variables:
lTmpBuff: PWord;
lBufSize: longword;
I: Integer;
--
Leonardo M. Ramé
http://leonardorame.blogspot.com
More information about the Lazarus
mailing list