sculpto
memory_swap.h
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file memory_swap.h
3 * \brief Memory swap function implementation module.
4 *
5 * \author Sabitov Kirill
6 * \date 28 June 2022
7 *********************************************************************/
8
9#pragma once
10
11#include "base.h"
12
13namespace scl
14{
15 /*!*
16 * Swap momory blocks function.
17 *
18 * \param BlockA - first memory block.
19 * \param BlockB - second memory block.
20 * \param Size - blocks size in bytes.
21 * \return None.
22 */
23 inline void MemorySwap(void *BlockA, void *BlockB, size_t Size)
24 {
25 u8 *a_swap = (u8 *)BlockA, *b_swap = (u8 *)BlockB;
26 u8 *a_end = a_swap + Size;
27
28 while (a_swap < a_end)
29 {
30 char temp = *a_swap;
31 *a_swap = *b_swap;
32 *b_swap = temp;
33
34 a_swap++, b_swap++;
35 }
36 }
37
38#define SCL_MEMORY_SWAP(BlockA, BlockB) \
39 SCL_CORE_ASSERT(sizeof(*BlockA) == sizeof(*BlockB), \
40 "Swaping memory blocks are of diffrent size!"); \
41 MemorySwap((void*)BlockA,(void*)BlockB, sizeof(*BlockA))
42
43}
Topology object basis class for mesh creating implementation module.
Definition: base.h:33
uint8_t u8
Definition: math_common.h:17
void MemorySwap(void *BlockA, void *BlockB, size_t Size)
Definition: memory_swap.h:23