Completely remove irrAllocator

This commit is contained in:
sfan5 2022-12-23 19:56:21 +01:00
parent 07fd32da50
commit 05a00a8d91
6 changed files with 189 additions and 372 deletions

View File

@ -9,7 +9,6 @@
#include "position2d.h" #include "position2d.h"
#include "rect.h" #include "rect.h"
#include "SColor.h" #include "SColor.h"
#include "irrAllocator.h"
#include <string.h> #include <string.h>
namespace irr namespace irr
@ -44,7 +43,7 @@ public:
delete[] Data; delete[] Data;
if (DeleteMipMapsMemory) if (DeleteMipMapsMemory)
Allocator.deallocate(MipMapsData); delete[] MipMapsData;
} }
//! Returns the color format //! Returns the color format
@ -275,13 +274,13 @@ public:
will by copied internally. will by copied internally.
\param deleteMemory Whether the memory is deallocated upon \param deleteMemory Whether the memory is deallocated upon
destruction. */ destruction. */
void setMipMapsData(void* data, bool ownForeignMemory, bool deleteMemory) void setMipMapsData(void* data, bool ownForeignMemory)
{ {
if (data != MipMapsData) if (data != MipMapsData)
{ {
if (DeleteMipMapsMemory) if (DeleteMipMapsMemory)
{ {
Allocator.deallocate(MipMapsData); delete[] MipMapsData;
DeleteMipMapsMemory = false; DeleteMipMapsMemory = false;
} }
@ -292,7 +291,7 @@ public:
{ {
MipMapsData = static_cast<u8*>(data); MipMapsData = static_cast<u8*>(data);
DeleteMipMapsMemory = deleteMemory; DeleteMipMapsMemory = false;
} }
else else
{ {
@ -311,7 +310,7 @@ public:
dataSize += getDataSizeFromFormat(Format, width, height); dataSize += getDataSizeFromFormat(Format, width, height);
} while (width != 1 || height != 1); } while (width != 1 || height != 1);
MipMapsData = Allocator.allocate(dataSize); MipMapsData = new u8[dataSize];
memcpy(MipMapsData, data, dataSize); memcpy(MipMapsData, data, dataSize);
DeleteMipMapsMemory = true; DeleteMipMapsMemory = true;
@ -578,7 +577,6 @@ protected:
bool DeleteMemory; bool DeleteMemory;
bool DeleteMipMapsMemory; bool DeleteMipMapsMemory;
core::irrAllocator<u8> Allocator;
#if defined(IRRLICHT_sRGB) #if defined(IRRLICHT_sRGB)
int Format_sRGB; int Format_sRGB;
#endif #endif

View File

@ -331,7 +331,7 @@ namespace video
_IRR_DEPRECATED_ ITexture* addTexture(const io::path& name, IImage* image, void* mipmapData) _IRR_DEPRECATED_ ITexture* addTexture(const io::path& name, IImage* image, void* mipmapData)
{ {
if (image) if (image)
image->setMipMapsData(mipmapData, false, true); image->setMipMapsData(mipmapData, false);
return addTexture(name, image); return addTexture(name, image);
} }

View File

@ -6,7 +6,6 @@
#define __S_MATERIAL_LAYER_H_INCLUDED__ #define __S_MATERIAL_LAYER_H_INCLUDED__
#include "matrix4.h" #include "matrix4.h"
#include "irrAllocator.h"
namespace irr namespace irr
{ {
@ -69,8 +68,7 @@ namespace video
{ {
if ( TextureMatrix ) if ( TextureMatrix )
{ {
MatrixAllocator.destruct(TextureMatrix); delete TextureMatrix;
MatrixAllocator.deallocate(TextureMatrix);
} }
} }
@ -90,8 +88,7 @@ namespace video
*TextureMatrix = *other.TextureMatrix; *TextureMatrix = *other.TextureMatrix;
else else
{ {
MatrixAllocator.destruct(TextureMatrix); delete TextureMatrix;
MatrixAllocator.deallocate(TextureMatrix);
TextureMatrix = 0; TextureMatrix = 0;
} }
} }
@ -99,8 +96,7 @@ namespace video
{ {
if (other.TextureMatrix) if (other.TextureMatrix)
{ {
TextureMatrix = MatrixAllocator.allocate(1); TextureMatrix = new core::matrix4(*other.TextureMatrix);
MatrixAllocator.construct(TextureMatrix,*other.TextureMatrix);
} }
else else
TextureMatrix = 0; TextureMatrix = 0;
@ -122,8 +118,7 @@ namespace video
{ {
if (!TextureMatrix) if (!TextureMatrix)
{ {
TextureMatrix = MatrixAllocator.allocate(1); TextureMatrix = new core::matrix4();
MatrixAllocator.construct(TextureMatrix,core::IdentityMatrix);
} }
return *TextureMatrix; return *TextureMatrix;
} }
@ -146,8 +141,7 @@ namespace video
{ {
if (!TextureMatrix) if (!TextureMatrix)
{ {
TextureMatrix = MatrixAllocator.allocate(1); TextureMatrix = new core::matrix4(mat);
MatrixAllocator.construct(TextureMatrix,mat);
} }
else else
*TextureMatrix = mat; *TextureMatrix = mat;
@ -216,7 +210,6 @@ namespace video
private: private:
friend class SMaterial; friend class SMaterial;
irr::core::irrAllocator<irr::core::matrix4> MatrixAllocator;
//! Texture Matrix //! Texture Matrix
/** Do not access this element directly as the internal /** Do not access this element directly as the internal

View File

@ -1,113 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine" and the "irrXML" project.
// For conditions of distribution and use, see copyright notice in irrlicht.h and irrXML.h
#ifndef __IRR_ALLOCATOR_H_INCLUDED__
#define __IRR_ALLOCATOR_H_INCLUDED__
#include "irrTypes.h"
#include <new>
// necessary for older compilers
#include <memory.h>
namespace irr
{
namespace core
{
//! Very simple allocator implementation, containers using it can be used across dll boundaries
template<typename T>
class irrAllocator
{
public:
//! Destructor
virtual ~irrAllocator() {}
//! Allocate memory for an array of objects
T* allocate(size_t cnt)
{
return (T*)internal_new(cnt* sizeof(T));
}
//! Deallocate memory for an array of objects
void deallocate(T* ptr)
{
internal_delete(ptr);
}
//! Construct an element
void construct(T* ptr, const T&e)
{
new ((void*)ptr) T(e);
}
//! Destruct an element
void destruct(T* ptr)
{
ptr->~T();
}
protected:
virtual void* internal_new(size_t cnt)
{
return operator new(cnt);
}
virtual void internal_delete(void* ptr)
{
operator delete(ptr);
}
};
//! Fast allocator, only to be used in containers inside the same memory heap.
/** Containers using it are NOT able to be used it across dll boundaries. Use this
when using in an internal class or function or when compiled into a static lib */
template<typename T>
class irrAllocatorFast
{
public:
//! Allocate memory for an array of objects
T* allocate(size_t cnt)
{
return (T*)operator new(cnt* sizeof(T));
}
//! Deallocate memory for an array of objects
void deallocate(T* ptr)
{
operator delete(ptr);
}
//! Construct an element
void construct(T* ptr, const T&e)
{
new ((void*)ptr) T(e);
}
//! Destruct an element
void destruct(T* ptr)
{
ptr->~T();
}
};
//! defines an allocation strategy (used only by irr::array so far)
enum eAllocStrategy
{
ALLOC_STRATEGY_SAFE = 0, // increase size by 1
ALLOC_STRATEGY_DOUBLE = 1, // double size when under 500 elements, beyond that increase by 1/4th size. Plus a small constant.
ALLOC_STRATEGY_SQRT = 2 // not implemented
};
} // end namespace core
} // end namespace irr
#endif

File diff suppressed because it is too large Load Diff

View File

@ -82,7 +82,7 @@ public:
{ {
if ( OriginalSize == Size && OriginalColorFormat == ColorFormat ) if ( OriginalSize == Size && OriginalColorFormat == ColorFormat )
{ {
Images[i]->setMipMapsData( images[i]->getMipMapsData(), false, true); Images[i]->setMipMapsData( images[i]->getMipMapsData(), false);
} }
else else
{ {