Howto? split and use a char array

This is a discussion on Howto? split and use a char array within the C++ Programming forums, part of the General Programming Boards category; You must use delete [] instead of delete to get rid of the allocated memory since you're using new []. ...

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,029
    You must use delete [] instead of delete to get rid of the allocated memory since you're using new []. Come to think of that, Why not just use the vector since you've already stored all the data?
    Code:
    unsigned int value = *(reinterpret_cast<unsigned int*>(&fullVVuffer[0]));
    Eliminates the copying-
    And why one byte at a time? If you know how much it's going to be, why not read X bytes at a time? It may be a little trickier, but it will improve performance. If you don't know the size, read in chunks until you have no more to read.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Jul 2010
    Posts
    9
    No problem, I'm trying to make my code clear and understandable for everyone.. Maybe it wasn't clear that i was sending an integer.. In a later stadium this bytearray will be filled with more values, that need to be split on the server.. this splitting is another issue, which is an issue that i will try to resolve as well. Do keep in mind that i just want unsigned bytes to be sent from the client.. I'm just trying stuff at the moment to find what fits the most..

    The endian issue won't be a problem, and I thank you for the code.. allthough i do not fully understand the while loop.. I'll spend some more time on vectors if someone else has other ideas, they are all welcome..

    @ Elysia..

    How would it be possible to read multiple bytes? Lets say I want to read the first 4 bytes every time.. How would this be done??

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,029
    I'm not well familiar with sockets, but I assume there's an argument that takes the number of bytes to read?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,812
    There is ways to specify the buffer size and I didn't feel like writing the code to fill the vector with multiple chars .

    But you can't always assume you get what you ask for. So you need to process what you are giving by the return value of recv.
    Woop?

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21