By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,714 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,714 IT Pros & Developers. It's quick & easy.

variable Bytes question

P: n/a
hi, to get the bytes sent by a socket, in VB a simple local variable like
below was used

Dim recv as Byte()

how can i do that in C++...this is what i am trying now

Byte * rec[] = new Bytes;

but i get these errors:

x:\User\FinalProject\Battleship\NewGame.h(180): error C2691: 'unsigned char
__gc *' : invalid type for __gc array element
x:\User\FinalProject\Battleship\NewGame.h(180): error C2061: syntax error :
identifier 'Bytes'

how can i get the bytes variable so i can receive the text sent by the other
connected socket? thanks

--
-iwdu15
Jan 9 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
this will give you a simple array of bytes.

Byte test[] = new Byte[1];
Byte test2 = 'A';

test[0] = test2;
kind regards,
Bruno.
"iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
news:E7**********************************@microsof t.com...
hi, to get the bytes sent by a socket, in VB a simple local variable like
below was used

Dim recv as Byte()

how can i do that in C++...this is what i am trying now

Byte * rec[] = new Bytes;

but i get these errors:

x:\User\FinalProject\Battleship\NewGame.h(180): error C2691: 'unsigned
char
__gc *' : invalid type for __gc array element
x:\User\FinalProject\Battleship\NewGame.h(180): error C2061: syntax error
:
identifier 'Bytes'

how can i get the bytes variable so i can receive the text sent by the
other
connected socket? thanks

--
-iwdu15

Jan 9 '06 #2

P: n/a
but then wat if wats received is ghreater than 100 bytes? the vb declaration
didnt have a constraint....is there anywasy to do that or do i have to limit
how much i send?
--
-iwdu15
Jan 10 '06 #3

P: n/a
iwdu15 wrote:
but then wat if wats received is ghreater than 100 bytes? the vb declaration
didnt have a constraint....is there anywasy to do that or do i have to limit
how much i send?


100 bytes? Bruno's example was a one byte array. But anyway, the trick
to not overflowing an array is to not read more bytes than can fit in it.

doug
Jan 10 '06 #4

P: n/a
if possible, always work with a fixed buffer size.
this will be more performant than always allocating and de-allocating buffers.

i don't know what you intend to send, but if it is not too much, just
allocate an array that will always be big enough. use a 1 MB buffer if that
solves you problem.
IMO that is a much better solution than having to manage variable length
buffers.

having to add xxx lines of memory management code to save a few bytes of
data is not worth it in most cases.
but in all cases, check the array size before you write data to it.

kind regards,
Bruno.

"iwdu15" wrote:
but then wat if wats received is ghreater than 100 bytes? the vb declaration
didnt have a constraint....is there anywasy to do that or do i have to limit
how much i send?
--
-iwdu15

Jan 10 '06 #5

P: n/a
ok, thanks alot
--
-iwdu15
Jan 11 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.