Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7992571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:36:03+00:00 2026-06-04T13:36:03+00:00

I have an OpenGL program, but can’t alloc correctly. m_VertexData = (GLfloat*)malloc(sizeof(m_TempVertexData)); m_NormalData =

  • 0

I have an OpenGL program, but can’t alloc correctly.

m_VertexData = (GLfloat*)malloc(sizeof(m_TempVertexData));
m_NormalData = (GLfloat*)malloc(sizeof(m_TempNormalData));
NSLog(@"sizeOfTempVertex: %d sizeOfTempNormal: %d", sizeof(m_TempVertexData),sizeof(m_TempNormalData));
NSLog(@"sizeOfVertex: %d sizeOfNormal: %d",sizeof(m_VertexData),sizeof(m_NormalData));

NSLog:

sizeOfTempVertex: 432 sizeOfTempNormal: 432

sizeOfVertex: 4 sizeOfNormal: 4

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:36:05+00:00Added an answer on June 4, 2026 at 1:36 pm

    m_VertexData and m_normalData are pointers, so their size is sizeof (whatever type it has *), so it allocates the correct amount of memory. You need to allocate sizeof(member of the array) * number of items bytes of memory. By the way, a few things related to malloc:

    1. Don’t cast the return value of malloc. It makes code unreadable and it’s unnecessary as void * is implicitly promoted to whatever pointer type it is assigned to.
    2. Don’t use sizeof(type), rather sizeof(variable). If you ever change the type of the variable, it’s gonna cause hard-to-track-down errors.

    Considering these points, use the following code:

    m_VertexData = malloc(sizeof(*m_VertexData) * numberOfItems);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple openGL D program that compiles, but I can't get it
I have a simple openGL D program that compiles, but I can't get it
I have an OpenGL-program using GLSL, that I can run just fine with the
I want to compile an OpenGL program but I don't have the necessary headers.
I have written a simple OpenGL program in C++ that displays a line joining
i have made a small opengl program using the d programming language. what i
I have a program (NWShader) which hooks into a second program's OpenGL calls (NWN)
I'm developing an OpenGL-ES game of life program for the iPhone and I have
I'm trying to transform vertices with a shader program, but i can't understand the
I have a program that uses GLUT for its OpenGL rendering. Now I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.