malloc issue

OK, thanks for letting us know.

ArthurD:
but then it's the same fault as before

So if fixing the obvious errors in the part of the code we were shown doesn't fix the problem it seems likely that there are errors in the part of the code we have not been shown.

I linked to the complete code already here: malloc issue - #6 by ArthurD - Jobs and Paid Consultancy - Arduino Forum

Sorry, don't read German too well.

like me for English :smiley:

but it's just about the malloc and the memcpy thing, and that's just C.

So, when you post a single sketch (here, obviously) that demonstrates the problem, I'll comment.

Who knows, in working through your problem, you may find the answer.

what?

I linked to all the code. If you can't help or if you're too lazy to start thinking about it, just let it be - maybe someone else finds the mistake.

The forum editor stupidly does not allow to post it here in a code box.

I meanwhile assume that it's a native Arduino compile error, it seems on the Pi I don't get that error.
(I use IDE 1.6.5)

If you can't be bothered to help others to help you, or you're too lazy to try, please stay over at the toy forum.

what?
that sounds like rubbish - what do you want to communicate?

If you do not want to help, please keep off of this topic.

I meanwhile assume that it's a native Arduino compile error,

Google "Hanlon's Razor"

why should I? I don't feel like discussion on your assulting and redicule level.
Help - or be quiet.

sp. "ridicule"

HTH

yes, ridicule, sorry for my poor English.

But please, back to topic.
A moderator should know about that. (CMIIW).

Yes, back to topic.

Now, where's the minimal sketch you wrote that demonstrates your problem?
(And if the answer is "it's on another forum or WasteBin, or a .doc, or I haven't written one", don't bother answering)

there is no minimal sketch, because the sketch is long, and the question is just about a small problem which I already cited:

http://forum.arduino.cc/index.php?topic=409498.msg2817956#msg2817956

http://forum.arduino.cc/index.php?topic=409498.msg2817997#msg2817997

the code works fine with a global int16_t buf[256],
but does not work with a dynamic allocated int16_t buf[256]

the complete code is here:

Then make a minimal sketch! We all have lives, too. A minimal sketch might also show you where the problem lies. If you don't want our help, that's fine, you are free to stay here and talk to yourself.

ArthurD:
the code works fine with a global int16_t buf[256],
but does not work with a dynamic allocated int16_t buf[256]

Does the global array version still work fine when 'buf' is a pointer to the global data?

int16_t myBuffer[256];
int16_t *buf = myBuffer;

Testing that would, at least, see if the problem was in the differences between an array and a pointer. If so, the problem could be in your pointer use, not necessarily in where your data is stored.

ArthurD:
thank you!
but with the global array memcpy works, but not with the malloc array...

why is that so?

Because a variable of type 'array of thing' is not the same as a variable of type 'pointer to thing'. However, the evalutaed rvalue of an array is a pointer to its first element. This makes a number of things super convenient and easy to code, but it can confuse you if you don't understand the distinction.

edit: I will try some things about the differences between an array and a pointer later and report then...

ps:
the problem is not about the array which is passed as a pointer - this part is always fine.
The problem is just about the buffer array which is needed for intermediate memcpy purposes and which has to be of the same size as the array size which is passed.
Only this dynamical generated buffer does not work with the memset and memcpy functions, but the global static array (arrlen=256)
int16_t buf[256]
works fine as a buffer nevertheless at any time.

So how can I generate a dynamical
int16_t buf array of the variable lenght "arrlen" which will work then with these 3 lines?

  memset(buf, 0, sizeof(buf) );  // clear buf array by Zeros
  for (i=signalstart; i<=signalend; ++i) buf[i-signalstart]=array[i]; // copy a small range from array to buf
  memcpy(array, buf, sizeof (buf)); // altern.: memcpy(array, buf, arrlen * sizeof (int16_t));
  // copy the "new" buf back to the original array

What is "buf"?

Why are you posting snippets, and not a minimal sketch which demonstrates your problem?