Commit: b9ac83ce9d7e03a549acaf4173429865aadbd70c
Author: Mike Erwin
Date:   Thu Apr 23 05:36:59 2015 -0400
Branches: GPU_data_request
https://developer.blender.org/rBb9ac83ce9d7e03a549acaf4173429865aadbd70c

single alloc per VertexBuffer, down from 2

Using flexible array member from C99.

Tested on LLVM/clang, also supported in GCC and MSVC according to docs:

https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
https://msdn.microsoft.com/en-us/library/b6fae073.aspx

===================================================================

M       source/blender/gpu/intern/gpux_vbo.c

===================================================================

diff --git a/source/blender/gpu/intern/gpux_vbo.c 
b/source/blender/gpu/intern/gpux_vbo.c
index 008b76b..84eb97d 100644
--- a/source/blender/gpu/intern/gpux_vbo.c
+++ b/source/blender/gpu/intern/gpux_vbo.c
@@ -82,10 +82,10 @@ struct VertexBuffer
 {
        unsigned attrib_ct; /* 1 to 16 */
        unsigned vertex_ct;
-       Attrib *attribs;
 #ifdef USE_VAO
        GLuint vao_id;
 #endif /* USE_VAO */
+       Attrib attribs[]; /* flexible array */
 };
 
 #ifdef PRINT
@@ -145,14 +145,12 @@ void GPUx_attrib_print(const VertexBuffer *buff, unsigned 
attrib_num)
 
 VertexBuffer *GPUx_vertex_buffer_create(unsigned a_ct, unsigned v_ct)
 {
-       VertexBuffer *buff = MEM_callocN(sizeof(VertexBuffer), "VertexBuffer");
+       VertexBuffer *buff = MEM_callocN(offsetof(VertexBuffer, attribs) + a_ct 
* sizeof(Attrib), "VertexBuffer");
 #ifdef TRUST_NO_ONE
        BLI_assert(a_ct >= 1 && a_ct <= 16);
 #endif /* TRUST_NO_ONE */
        buff->attrib_ct = a_ct;
        buff->vertex_ct = v_ct;
-       buff->attribs = MEM_callocN(a_ct * sizeof(Attrib), 
"VertexBuffer.attribs");
-       /* TODO: single allocation instead of 2 */
        return buff;
 }
 
@@ -175,7 +173,6 @@ void GPUx_vertex_buffer_discard(VertexBuffer *buff)
        if (buff->vao_id)
                vao_id_free(buff->vao_id);
 #endif /* USE_VAO */
-       MEM_freeN(buff->attribs);
        MEM_freeN(buff);
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to