LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

memcpy limitation

Hello all,
In my CVI 7.1 application I have to copy some stuff. The original code I got from another department has:

void dec_fMemCpy( void * pvDest, void * pvSource, int iSize )
{
    char * pubySrc;
    char * pubyDest;
    int i;

    pubysrc=(char *)pvSource;
    pubyDest = (char *)pvDest;

    for(i=0; i<iSize; i++)
    {
        *pubyDest = *pubySrc;
        pubyDest++;
        pubySrc++;
    }
}


With that I get an "Array out of bounds Error" when iSize > 6144.

I tried memcpy instead and face the same problem:

 FATAL RUN-TIME ERROR:   "storm_decoder.c", line 1660, col 13, thread id 0x000002A4:   Array argument too small (6144 bytes).  Argument must contain at least 10796 bytes (10796 elements).

The code works in different environments. Is there a special reason for that CVI delicacy? And what can be a way to handle that issue?

Best regrads,
ah



0 Kudos
Message 1 of 5
(4,250 Views)

I think we need to see details of the code that calls this function, and any associated variable declarations, before deciding on the source of the problem.

JR

0 Kudos
Message 2 of 5
(4,242 Views)
Hello JR,
I have to say I'm a bit confused. After your post I made a test and twice malloced 10700 Bytes and memseted them with data (0xAA and 0x55). Than I copied one block to the other - and it worked.
In the application what is to be copied is a struct with arrays of structs, pointers to funkctions &c. But what makes the difference and why only to CVI? In my understanding, the copy function just gets two pointers and the amount of data (number of bytes) to be copied.
Best regards
ah
0 Kudos
Message 3 of 5
(4,210 Views)
If you build a CVI program in Debug mode, then more information is passed to function calls than just the explicit parameter list as defined in the source code. CVI inserts this information in a transparant fashion, to help locate programming errors. In your "copy" case, there will be additional information for example on how much valid memory is being pointed to by each pointer - thus allowing the debugger to check that the function will not corrupt memory that it should not touch. This is why I asked for the calling code - CVI extracts the size information at the point of the function call, from the definition of the variables involved.
 
This only applies for Debug: for Release there are no extra hidden parameters and your copy function would be free to corrupt whatever memory it chooses to, in the event of some error.
 
JR
0 Kudos
Message 4 of 5
(4,202 Views)
JR,
that realy helped me!
Thank you for the detailed information.
ah

0 Kudos
Message 5 of 5
(4,193 Views)