Commit 7e9b13b5 by Olli Etuaho Committed by Commit Bot

Add helper function to pool allocate a char array

This makes it easier to allocate char arrays in the memory pool. TEST=angle_unittests BUG=angleproject:2267 Change-Id: I1673330f58968ea9d38c671b70a7a489276af863 Reviewed-on: https://chromium-review.googlesource.com/883805Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent c081020c
...@@ -121,6 +121,17 @@ inline TString str(T i) ...@@ -121,6 +121,17 @@ inline TString str(T i)
return buffer; return buffer;
} }
// Allocate a char array in the global memory pool. str must be a null terminated string. strLength
// is the length without the null terminator.
inline const char *AllocatePoolCharArray(const char *str, size_t strLength)
{
size_t requiredSize = strLength + 1;
char *buffer = reinterpret_cast<char *>(GetGlobalPoolAllocator()->allocate(requiredSize));
memcpy(buffer, str, requiredSize);
ASSERT(buffer[strLength] == 0);
return buffer;
}
} // namespace sh } // namespace sh
namespace std namespace std
......
...@@ -539,10 +539,7 @@ const char *TType::buildMangledName() const ...@@ -539,10 +539,7 @@ const char *TType::buildMangledName() const
mangledName += ';'; mangledName += ';';
// Copy string contents into a pool-allocated buffer, so we never need to call delete. // Copy string contents into a pool-allocated buffer, so we never need to call delete.
size_t requiredSize = mangledName.size() + 1; return AllocatePoolCharArray(mangledName.c_str(), mangledName.size());
char *buffer = reinterpret_cast<char *>(GetGlobalPoolAllocator()->allocate(requiredSize));
memcpy(buffer, mangledName.c_str(), requiredSize);
return buffer;
} }
size_t TType::getObjectSize() const size_t TType::getObjectSize() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment