janderkan Well-Known Member Licensed User Longtime User Jul 30, 2018 #1 This code from RH_RF95.h library works fine, but is there another way to copy the array? B4X: ArrayByte* RF95::getReceive() { Byte buffer[RH_RF95_MAX_MESSAGE_LEN]; Byte len = RH_RF95_MAX_MESSAGE_LEN; rf95->recv(buffer, &len); ArrayByte* arr = CreateStackMemoryObject(ArrayByte); arr->data = (StackMemory::buffer + StackMemory::cp); for (int i = 0;i < len; i++) { StackMemory::buffer[StackMemory::cp++] = buffer[i]; } arr->length=len; return arr; }
This code from RH_RF95.h library works fine, but is there another way to copy the array? B4X: ArrayByte* RF95::getReceive() { Byte buffer[RH_RF95_MAX_MESSAGE_LEN]; Byte len = RH_RF95_MAX_MESSAGE_LEN; rf95->recv(buffer, &len); ArrayByte* arr = CreateStackMemoryObject(ArrayByte); arr->data = (StackMemory::buffer + StackMemory::cp); for (int i = 0;i < len; i++) { StackMemory::buffer[StackMemory::cp++] = buffer[i]; } arr->length=len; return arr; }
Erel B4X founder Staff member Licensed User Longtime User Jul 31, 2018 #2 What is the problem with this code? It looks fine. You can use memcpy or memmove but the result will be the same.
What is the problem with this code? It looks fine. You can use memcpy or memmove but the result will be the same.