kupl_memcpy
Copy the memory from the src position to the dst position.
Interface Definition
int kupl_memcpy(void *dst, const void *src, size_t count);
- Currently, the maximum copy length supported by kupl_memcpy is UINT32_MAX. That is, the value of count cannot exceed UINT32_MAX.
- The value of count must be less than the actual size of the memory to which src and dst point.
Environment Variables
KUPL uses KUPL_MEMCPY_MT_THRESHOLD and KUPL_SDMA_MEMCPY_THRESHOLD to determine the packet size thresholds for the multi-thread memcpy capability and the SDMA memcpy capability, respectively. By default, the multi-thread memcpy threshold is 512 KB, and the SDMA memcpy threshold is 2 MB.
kupl_memcpy supports three methods: single-thread glibc memcpy, SDMA memcpy, and multi-thread memcpy. If SDMA is enabled in the environment, determine a memcpy method based on KUPL_SDMA_MEMCPY_THRESHOLD. Data packets smaller than this threshold use glibc memcpy; otherwise, SDMA memcpy is utilized. Similarly, if SDMA is disabled, use KUPL_MEMCPY_MT_THRESHOLD to determine a memcpy method. Data packets smaller than this threshold use glibc memcpy; otherwise, multi-thread memcpy is utilized.
You can define the thresholds for multi-thread memcpy and SDMA memcpy by configuring KUPL_MEMCPY_MT_THRESHOLD and KUPL_SDMA_MEMCPY_THRESHOLD. These configurations are also used by the kupl_memcpy2d interface to determine the optimal memcpy method.
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
dst |
void * |
Pointer to the destination location of the copied memory. |
Input/Output |
src |
const void * |
Pointer to the source location of memory to be copied. |
Input |
count |
size_t |
Size of the memory to be copied. |
Input |
Return Value
- Success: KUPL_OK
- Failure: KUPL_ERROR
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <stdio.h> #include <stdlib.h> #include <assert.h> #include "kupl.h" int main() { int len = 1024; char *src = (char *)kupl_malloc(KUPL_MEM_DEFAULT, len); char *dest = (char *)kupl_malloc(KUPL_MEM_DEFAULT, len); if (src == nullptr || dest == nullptr) { goto error; } for (int i = 0; i < len / sizeof(char); i++) { src[i] = i ; dest[i] = 0; } int ret = kupl_memcpy(dest, src, len); assert(ret == KUPL_OK); error: kupl_free(KUPL_MEM_DEFAULT, src); kupl_free(KUPL_MEM_DEFAULT, dest); return 0; } |
- The preceding example demonstrates the memory copy process.
- The kupl_memcpy function copies the content in the src array to the dest array. len represents the size of the copied memory.