0

I am getting wrong memcpy log .

i want to take *q (pointer on array in size inNumberOfFrames) .

i want to copy it each time to a new array buffersRing[ringNum][inNumberOfFrames] .

when in buffersRing[ringNum][0] i save q's size- inNumberOfFrames , and the rest of q is saved into buffersRing[ringNum][1]-buffersRing[ringNum][inNumberOfFrames] .

i do :

buffersRing[ringNum][0]=inNumberFrames;
memcpy(buffersRing[ringNum]+1, q, inNumberFrames);

i get wrong values. whats wrong here ?

EDIT:

but doing this instead of copy -works great :

 for( int k=1;k<inNumberFrames+1;k++)
     buffersRing[ringNum][k]=q[k-1];
  • 1
    What type is `buffersRing` ? How about `inNumberFrames` ? – cnicutar Jan 21 '13 at 17:49
  • Can you show the relevant code instead of trying to phrase it? – netcoder Jan 21 '13 at 17:50
  • int16_t buffersRing , and int inNumberFrames –  Jan 21 '13 at 17:51
  • @netcoder this is the actually code. just a copy past –  Jan 21 '13 at 17:51
  • you right, but see my edit . in this question i am trying to compare between 2 ways. if you know the second way i have posted is working, than you actually dont need more info. am i wrong ? –  Jan 21 '13 at 17:58

2 Answers2

0

I believe the call to memcpy() should be:

memcpy(buffersRing[ringNum]+1, q, inNumberFrames * sizeof *q);

since you want to copy inNumberFrames times the number of bytes occupied by one element of q.

Alok Singhal
  • 93,253
  • 21
  • 125
  • 158
  • actually if i think again i am not sure its true. every time i get q i get also its size inNumFrames. so q has inNumOfFrames samples. when you copy you give the index number am i wrong ? –  Jan 21 '13 at 18:11
0

It looks like the source and destination of your memcpy call do overlap.

You should call memmove in such cases.

Didier Trosset
  • 36,376
  • 13
  • 83
  • 122
  • the *q i get is an audio buffer of hardware device. you think moving it is the right way ? because previous answer did not work yet –  Jan 21 '13 at 18:04