acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
c_malloc.h
1// Created by camilo on 2023-11-24 22:26 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5#include <stdlib.h>
6
7
8namespace c
9{
10
11
12 class CLASS_DECL_ACME malloc
13 {
14 public:
15
16
17 template < typename T >
18 static T * create()
19 {
20
21 auto p = (T *) ::malloc(sizeof(T));
22
23 ::new(p)T();
24
25 return p;
26
27 }
28
29
30 template < typename T >
31 static T * construct(T * & p)
32 {
33
34 p = (T *) ::malloc(sizeof(T));
35
36 ::new(p)T();
37
38 return p;
39
40 }
41
42
43 template < typename T >
44 static void destroy(T *& p)
45 {
46
47 auto pdel = p;
48
49 p = nullptr;
50
51 pdel->~T();
52
53 ::free(pdel);
54
55 }
56
57 };
58
59
60} // namespace c
61
62
63
Definition c_malloc.h:13