mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
Better allocator for TorqueScript temp conversions used during interpretation
instead of using a Vector<> that never frees and grows for torquescript temporaries created when doing type conversions)
This commit is contained in:
parent
516163fd5d
commit
3988e7baee
3 changed files with 8 additions and 29 deletions
|
|
@ -46,29 +46,28 @@
|
||||||
extern StringStack STR;
|
extern StringStack STR;
|
||||||
extern ConsoleValueStack<4096> gCallStack;
|
extern ConsoleValueStack<4096> gCallStack;
|
||||||
|
|
||||||
Vector<ConsoleValue::ConversionBuffer> ConsoleValue::sConversionBuffer;
|
DataChunker ConsoleValue::sConversionAllocator;
|
||||||
|
|
||||||
void ConsoleValue::init()
|
void ConsoleValue::init()
|
||||||
{
|
{
|
||||||
sConversionBuffer.reserve(8192);
|
sConversionAllocator.setChunkSize(8092);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleValue::resetConversionBuffer()
|
void ConsoleValue::resetConversionBuffer()
|
||||||
{
|
{
|
||||||
sConversionBuffer.resetAndTreatAsScratchBuffer();
|
sConversionAllocator.freeBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
char* ConsoleValue::convertToBuffer() const
|
char* ConsoleValue::convertToBuffer() const
|
||||||
{
|
{
|
||||||
ConversionBuffer conversion;
|
char* buffer = static_cast<char*>(sConversionAllocator.alloc(32));
|
||||||
|
|
||||||
if (type == ConsoleValueType::cvFloat)
|
if (type == ConsoleValueType::cvFloat)
|
||||||
dSprintf(conversion.buffer, ConversionBufferStride, "%.9g", f);
|
dSprintf(buffer, 32, "%.9g", f);
|
||||||
else
|
else
|
||||||
dSprintf(conversion.buffer, ConversionBufferStride, "%lld", i);
|
dSprintf(buffer, 32, "%lld", i);
|
||||||
|
|
||||||
sConversionBuffer.push_back(std::move(conversion));
|
return buffer;
|
||||||
return sConversionBuffer.last().buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* ConsoleValue::getConsoleData() const
|
const char* ConsoleValue::getConsoleData() const
|
||||||
|
|
|
||||||
|
|
@ -146,17 +146,7 @@ class ConsoleValue
|
||||||
|
|
||||||
S32 type;
|
S32 type;
|
||||||
|
|
||||||
enum Constants
|
static DataChunker sConversionAllocator;
|
||||||
{
|
|
||||||
ConversionBufferStride = 32
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ConversionBuffer
|
|
||||||
{
|
|
||||||
char buffer[ConversionBufferStride];
|
|
||||||
};
|
|
||||||
|
|
||||||
static Vector<ConversionBuffer> sConversionBuffer;
|
|
||||||
|
|
||||||
char* convertToBuffer() const;
|
char* convertToBuffer() const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,6 @@ class Vector
|
||||||
void erase(U32 index, U32 count);
|
void erase(U32 index, U32 count);
|
||||||
void erase_fast(iterator);
|
void erase_fast(iterator);
|
||||||
void clear();
|
void clear();
|
||||||
void resetAndTreatAsScratchBuffer();
|
|
||||||
void compact();
|
void compact();
|
||||||
void sort(compare_func f);
|
void sort(compare_func f);
|
||||||
void fill( const T& value );
|
void fill( const T& value );
|
||||||
|
|
@ -530,15 +529,6 @@ template<class T> inline void Vector<T>::clear()
|
||||||
mElementCount = 0;
|
mElementCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method sets the vector as its 0 and will overwrite memory on subsequent usage.
|
|
||||||
/// Note that the current memory in use is never freed or deallocated, so only use this if the vector
|
|
||||||
/// is being used as a scratch buffer only.
|
|
||||||
template<class T> inline
|
|
||||||
void Vector<T>::resetAndTreatAsScratchBuffer()
|
|
||||||
{
|
|
||||||
mElementCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T> inline void Vector<T>::compact()
|
template<class T> inline void Vector<T>::compact()
|
||||||
{
|
{
|
||||||
resize(mElementCount);
|
resize(mElementCount);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue