login about faq

I am a little curious though as why you are returning the binary buffer data in an internal object format, which can't be used directly in Delphi, but have to be re-allocated in another library..?

From an application developer perspective, are there any uses for a buffer of HCkByteData or are there a way to transfer the data in the buffer without having it reallocated/copied in the CkByteData library ?

I'm thinking something like if the HCkSsh library just returned a pointer to a byte buffer or something, a memory stream even, from a Delphi perspective that would be the "normal" way of doing it..

It just seems to me like a lot of unnecessary memory copying, which in the end will affect the performance of the application, but hey, I can only see things from outside the white box

asked Mar 04 '14 at 10:03

chilkat's gravatar image

chilkat ♦♦
11.8k316358421


For binary data, Chilkat made a design decision to pass it contained within an object (CkByteData) as opposed to passing a memory pointer directly. In effect, this is really the identical design decision taken by .NET -- where arrays are actually objects. The reason has to do with the ability to provide the identical API across many different programming languages.

It is easy to pass data in without copying by using the borrowData method. When doing this, the CkByteData does not own the data, but simply points to it. If a CkByteData contains borrowed data, and then you try to modify the contents of the CkByteData (such as by appending, or deleting some portion of it), then the data is automatically copied to an internal buffer and modified. In other words, the CkByteData has no ability to modify the external memory that it points to.

Here is sample Delphi code demonstrating it:

procedure TForm1.demoBytes();
const
  aBytes : array[0..7] of byte = (0,1,2,3,4,5,6,7);
var
success: Boolean;

ckBytes: HCkByteData; pBytes: PByte; szBytes: Integer;

begin

ckBytes := CkByteData_Create();

// You may copy bytes into the CkByteData pBytes := Addr(aBytes); CkByteData_append2(ckBytes, pBytes,8);

// Alternatively, you may allow the CkByteData to borrow the bytes // meaning that it references the memory and does not copy. CkByteData_borrowData(ckBytes, pBytes,8);

// Direct access to the bytes is always possible: pBytes := CkByteData_getData(ckBytes); szBytes := CkByteData_getSize(ckBytes);

CkByteData_Dispose(ckBytes);

end;

link

answered Mar 04 '14 at 10:10

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×56
×10
×3
×1

Asked: Mar 04 '14 at 10:03

Seen: 1,354 times

Last updated: Mar 04 '14 at 10:10

powered by OSQA