mirror of
https://github.com/ZDoom/Raze.git
synced 2025-05-30 00:41:24 +00:00
- backend sync with GZDoom to pull in a few bugfixes and formatting corrections.
This commit is contained in:
parent
143e338d9f
commit
d52600663d
55 changed files with 1121 additions and 243 deletions
43
source/common/utility/r_memory.h
Normal file
43
source/common/utility/r_memory.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
// Memory needed for the duration of a frame rendering
|
||||
class RenderMemory
|
||||
{
|
||||
public:
|
||||
void Clear();
|
||||
|
||||
template<typename T>
|
||||
T *AllocMemory(int size = 1)
|
||||
{
|
||||
return (T*)AllocBytes(sizeof(T) * size);
|
||||
}
|
||||
|
||||
template<typename T, typename... Types>
|
||||
T *NewObject(Types &&... args)
|
||||
{
|
||||
void *ptr = AllocBytes(sizeof(T));
|
||||
return new (ptr)T(std::forward<Types>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
void *AllocBytes(int size);
|
||||
|
||||
enum { BlockSize = 1024 * 1024 };
|
||||
|
||||
struct MemoryBlock
|
||||
{
|
||||
MemoryBlock();
|
||||
~MemoryBlock();
|
||||
|
||||
MemoryBlock(const MemoryBlock &) = delete;
|
||||
MemoryBlock &operator=(const MemoryBlock &) = delete;
|
||||
|
||||
uint8_t *Data;
|
||||
uint32_t Position;
|
||||
};
|
||||
std::vector<std::unique_ptr<MemoryBlock>> UsedBlocks;
|
||||
std::vector<std::unique_ptr<MemoryBlock>> FreeBlocks;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue