1

This is my first post I hope I am not making any mistake. I have the following code. I am trying to allocate and access a two dimensional array in one shot and more importantly in one byte array. I also need to be able to access each sub array individually as shown in the code. It works fine in the debug mode. Though in the release build in VS 2012, it causes some problems during runtime, when the compiler optimizations are applied. If I disable the release compiler optimizations then it works. Do I need to do some kind of special cast to inform the compiler?

My priorities in code is fast allocation and network communication of complete array and at the same time working with its sub arrays.

I prefer not to use boost.

Thanks a lot :)

void PrintBytes(char* x,byte* data,int length)
{
    using namespace std;
    cout<<x<<endl;
    for(  int i = 0; i < length; i++ )
    {
        std::cout << "0x" << std::setbase(16) << std::setw(2) << std::setfill('0');
        std::cout << static_cast<unsigned int>( data[ i ] ) << " ";
    }
    std::cout << std::dec;
    cout<<endl;
}

byte* set = new byte[SET_SIZE*input_size];
for (int i=0;i<SET_SIZE;i++)
{
    sprintf((char*)&set[i*input_size], "M%06d", i+1);
}
PrintByte((byte*)&set[i*input_size]);

0 Answers0