-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
canard: use malloc and placement new instead of new
- Loading branch information
1 parent
47bcecb
commit d014d0b
Showing
6 changed files
with
50 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,38 @@ | ||
#pragma once | ||
|
||
#ifdef USE_USER_HELPERS | ||
#include "canard_helpers_user.h" | ||
#endif | ||
|
||
#ifndef NOINLINE_FUNC | ||
#define NOINLINE_FUNC __attribute__((noinline)) | ||
#endif | ||
|
||
// define malloc and free | ||
#ifndef CANARD_MALLOC | ||
#include <stdlib.h> | ||
#include <new> | ||
#define CANARD_MALLOC malloc | ||
#define CANARD_FREE free | ||
#endif | ||
|
||
namespace Canard { | ||
template<typename T, typename ...Args> | ||
T* allocate(Args...args) { | ||
auto ret = CANARD_MALLOC(sizeof(T)); | ||
if (ret == nullptr) { | ||
return nullptr; | ||
} | ||
return new(ret) T(args...); | ||
} | ||
|
||
template<typename T> | ||
void deallocate(T* ptr) { | ||
if (ptr == nullptr) { | ||
return; | ||
} | ||
ptr->~T(); | ||
CANARD_FREE(ptr); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters