Re: Problem with VS and memcpy...



Do you really have to use intermediate header[8], rather than set the bytes
directly in buffer?

"Paolo" <paomic@xxxxxxxxx> wrote in message
news:1151575114.297220.27410@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The excat code is:


int number = 25;
int offSet = 16000;
unsigned char header[8];
header[0] = 0;
header[1] = 255;
header[2] = 0;
header[3] = number>>8;
header[4] = number;
header[5] = offSet>>16;
header[6] = offSet>>8;
header[7] = offSet;

memcpy(buffer, header, sizeof header);


John Carson ha scritto:

"Paolo" <paomic@xxxxxxxxx> wrote in message
news:1151573245.812709.93530@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Yes I amde some mistakes in the code, I couldn't paste because it was
too long.

Yes, the correct lines are

unsigned char* buffer = new unsigned char[1000];

and

memcpy(buf, temp, sizeof temp);

I didn't use the redundant casts at first, but then I added them, but
nothing changed.

The problem isI just can't see why if I use the debugger before the
memcpy I can see something like

buffer = 0x01234456 "yqhsfjkvdfdsfhfe"

Where "yqhsfjkvdfdsfhfe" ius the content of the buffer, but after
thememcpy it becomes

buffer = 0x01234456 ""

Is it normal?

The content of buffer will only be displayed up until the first
terminating
zero. It looks to me like temp has a terminating zero (i.e., '\0') as its
first character.

You need to give us code that actually exhibits the problem (and no other
problem). Code that looks like your code but doesn't have the problem is
useless.

--
John Carson



.



Relevant Pages

  • Re: InputStream
    ... Especially if reading from a network connection or ... > The displayed message always says that the read amount is lower than the ... read(bytebuffer, int offset, int maxWanted) is for doing this. ...
    (comp.lang.java.programmer)
  • Re: Problem with VS and memcpy...
    ... memcpy(buf, temp, sizeof temp); ... Where "yqhsfjkvdfdsfhfe" ius the content of the buffer, ... The content of buffer will only be displayed up until the first terminating ... It looks to me like temp has a terminating zero ...
    (microsoft.public.vc.language)
  • Can NetworkStream.Write() block?
    ... myNetworkStream.Write(byte, int offset, int size); ... From the MSDN documentation: ... If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code, and refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error. ... It says the call blocks until the bytes are sent but aren't the bytes just queued to the write buffer until the OS feels like sending them over the wire? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can NetworkStream.Write() block?
    ... myNetworkStream.BeginWrite(bytebuffer, int offset, int size) since all that does is create a backlog of BeginWrite threads all waiting to complete. ... In general, you can assume asynchronous calls are *more* efficient than their synchronous companions, since those *always* take up a thread (namely the thread waiting for completion) while the asynchronous ones generally only take up a thread when executing the completion callback. ... The overlapped requests are simply queued until there's an opportunity to process them. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Generics Questions
    ... What am I missing? ... public class SingleByteConverter: IByteConverter{ ... public int WriteToBuffer(float value, bytebuffer, int offset) { ...
    (microsoft.public.dotnet.languages.csharp)

Loading