Variable Size Array

  • Thread starter Thread starter Kevin Frey
  • Start date Start date
K

Kevin Frey

Hello,

I want to do the equivalent of this in Managed C++:

void MyFunc( int n )
{
Byte[ ] mybuffer = new Byte[ n ];

socket.Receive( mybuffer ... );
}

The key point here is that I want to allocate an array of Bytes according to
a variable, not a constant-sized array.

The compiler complains that n is not constant. For our TCP communications
(porting from unmanaged C++) all of our packets are length prefixed, so we
read the length, then allocate the right amount of space for the buffer.

Can someone tell me how to achieve this?

Thanks

Kevin.
 
Hello,

void MyFunc( int n )
{
char *mybuffer = new char[ n ];
socket.Receive( mybuffer ... );
}
 
lallous said:
Hello,

void MyFunc( int n )
{
char *mybuffer = new char[ n ];
socket.Receive( mybuffer ... );
}

--
Elias
Kevin Frey said:
Hello,

I want to do the equivalent of this in Managed C++:

void MyFunc( int n )
{
Byte[ ] mybuffer = new Byte[ n ];

socket.Receive( mybuffer ... );
}

The key point here is that I want to allocate an array of Bytes
according
to
a variable, not a constant-sized array.

The compiler complains that n is not constant. For our TCP communications
(porting from unmanaged C++) all of our packets are length prefixed, so we
read the length, then allocate the right amount of space for the buffer.

Totally OT...

How do you handle the case of a faked packet with a false length (too
small)? :-)


Bo Persson
 
Back
Top