Core: Replace StackAllocation by StackArray
This will cleanup alloca usage a little bit
This commit is contained in:
@@ -566,8 +566,7 @@ namespace Nz
|
||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||
NazaraAssert(buffers && bufferCount > 0, "Invalid buffers");
|
||||
|
||||
StackAllocation memory = NazaraStackAllocation(bufferCount * sizeof(iovec));
|
||||
struct iovec* sysBuffers = static_cast<struct iovec*>(memory.GetPtr());
|
||||
StackArray<iovec> sysBuffers = NazaraStackAllocation(iovec, bufferCount);
|
||||
for (std::size_t i = 0; i < bufferCount; ++i)
|
||||
{
|
||||
sysBuffers[i].iov_base = buffers[i].data;
|
||||
@@ -577,7 +576,7 @@ namespace Nz
|
||||
struct msghdr msgHdr;
|
||||
std::memset(&msgHdr, 0, sizeof(msgHdr));
|
||||
|
||||
msgHdr.msg_iov = sysBuffers;
|
||||
msgHdr.msg_iov = sysBuffers.data();
|
||||
msgHdr.msg_iovlen = static_cast<int>(bufferCount);
|
||||
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
@@ -689,8 +688,7 @@ namespace Nz
|
||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||
NazaraAssert(buffers && bufferCount > 0, "Invalid buffers");
|
||||
|
||||
StackAllocation memory = NazaraStackAllocation(bufferCount * sizeof(iovec));
|
||||
struct iovec* sysBuffers = static_cast<struct iovec*>(memory.GetPtr());
|
||||
StackArray<iovec> sysBuffers = NazaraStackAllocation(iovec, bufferCount);
|
||||
for (std::size_t i = 0; i < bufferCount; ++i)
|
||||
{
|
||||
sysBuffers[i].iov_base = buffers[i].data;
|
||||
@@ -703,7 +701,7 @@ namespace Nz
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
msgHdr.msg_namelen = IpAddressImpl::ToSockAddr(to, nameBuffer.data());
|
||||
msgHdr.msg_name = nameBuffer.data();
|
||||
msgHdr.msg_iov = sysBuffers;
|
||||
msgHdr.msg_iov = sysBuffers.data();
|
||||
msgHdr.msg_iovlen = static_cast<int>(bufferCount);
|
||||
|
||||
int byteSent = sendmsg(handle, &msgHdr, MSG_NOSIGNAL);
|
||||
|
||||
@@ -596,8 +596,7 @@ namespace Nz
|
||||
|
||||
IpAddress senderIp;
|
||||
|
||||
StackAllocation memory = NazaraStackAllocation(bufferCount * sizeof(WSABUF));
|
||||
WSABUF* winBuffers = static_cast<WSABUF*>(memory.GetPtr());
|
||||
StackArray<WSABUF> winBuffers = NazaraStackAllocation(WSABUF, bufferCount);
|
||||
for (std::size_t i = 0; i < bufferCount; ++i)
|
||||
{
|
||||
winBuffers[i].buf = static_cast<CHAR*>(buffers[i].data);
|
||||
@@ -606,7 +605,7 @@ namespace Nz
|
||||
|
||||
DWORD flags = 0;
|
||||
DWORD byteRead;
|
||||
if (WSARecvFrom(handle, winBuffers, static_cast<DWORD>(bufferCount), &byteRead, &flags, reinterpret_cast<sockaddr*>(nameBuffer.data()), &bufferLength, nullptr, nullptr) == SOCKET_ERROR)
|
||||
if (WSARecvFrom(handle, winBuffers.data(), static_cast<DWORD>(bufferCount), &byteRead, &flags, reinterpret_cast<sockaddr*>(nameBuffer.data()), &bufferLength, nullptr, nullptr) == SOCKET_ERROR)
|
||||
{
|
||||
int errorCode = WSAGetLastError();
|
||||
switch (errorCode)
|
||||
@@ -696,8 +695,7 @@ namespace Nz
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
int bufferLength = IpAddressImpl::ToSockAddr(to, nameBuffer.data());
|
||||
|
||||
StackAllocation memory = NazaraStackAllocation(bufferCount * sizeof(WSABUF));
|
||||
WSABUF* winBuffers = static_cast<WSABUF*>(memory.GetPtr());
|
||||
StackArray<WSABUF> winBuffers = NazaraStackAllocation(WSABUF, bufferCount);
|
||||
for (std::size_t i = 0; i < bufferCount; ++i)
|
||||
{
|
||||
winBuffers[i].buf = static_cast<CHAR*>(buffers[i].data);
|
||||
@@ -705,7 +703,7 @@ namespace Nz
|
||||
}
|
||||
|
||||
DWORD byteSent;
|
||||
if (WSASendTo(handle, winBuffers, static_cast<DWORD>(bufferCount), &byteSent, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength, nullptr, nullptr) == SOCKET_ERROR)
|
||||
if (WSASendTo(handle, winBuffers.data(), static_cast<DWORD>(bufferCount), &byteSent, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength, nullptr, nullptr) == SOCKET_ERROR)
|
||||
{
|
||||
int errorCode = WSAGetLastError();
|
||||
switch (errorCode)
|
||||
|
||||
@@ -44,12 +44,11 @@ namespace Nz
|
||||
{
|
||||
//TODO: constexpr if to prevent copy/cast if sizeof(cpVect) == sizeof(Vector2f)
|
||||
|
||||
StackAllocation stackAlloc = NazaraStackAllocation(vertexCount * sizeof(Vector2f));
|
||||
Vector2f* vec = static_cast<Vector2f*>(stackAlloc.GetPtr());
|
||||
StackArray<Vector2f> vertices = NazaraStackAllocation(Vector2f, vertexCount);
|
||||
for (int i = 0; i < vertexCount; ++i)
|
||||
vec[i].Set(float(vertices[i].x), float(vertices[i].y));
|
||||
vertices[i].Set(float(vertices[i].x), float(vertices[i].y));
|
||||
|
||||
drawOptions->polygonCallback(vec, vertexCount, float(radius), CpDebugColorToColor(outlineColor), CpDebugColorToColor(fillColor), drawOptions->userdata);
|
||||
drawOptions->polygonCallback(vertices.data(), vertexCount, float(radius), CpDebugColorToColor(outlineColor), CpDebugColorToColor(fillColor), drawOptions->userdata);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1762,9 +1762,7 @@ namespace Nz
|
||||
glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength);
|
||||
maxLength++;
|
||||
|
||||
StackAllocation stackAlloc = NazaraStackAllocation((maxLength + 1) * sizeof(GLchar));
|
||||
GLchar* nameBuffer = static_cast<GLchar*>(stackAlloc.GetPtr());
|
||||
|
||||
StackAllocation<GLchar> nameBuffer = NazaraStackAllocation(GLchar, maxLength + 1);
|
||||
for (GLint i = 0; i < count; i++)
|
||||
{
|
||||
GLint size;
|
||||
@@ -1772,9 +1770,9 @@ namespace Nz
|
||||
|
||||
glGetActiveUniform(program, i, maxLength, nullptr, &size, &type, nameBuffer);
|
||||
|
||||
dump << "Uniform #" << i << ": " << nameBuffer << "(Type: 0x" << String::Number(type, 16);
|
||||
dump << "Uniform #" << i << ": " << nameBuffer.data() << "(Type: 0x" << String::Number(type, 16);
|
||||
|
||||
GLint location = glGetUniformLocation(program, nameBuffer);
|
||||
GLint location = glGetUniformLocation(program, nameBuffer.data());
|
||||
switch (type)
|
||||
{
|
||||
case GL_FLOAT:
|
||||
|
||||
Reference in New Issue
Block a user