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

  • SEARCH
  • Home
  • 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 8671715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:01:03+00:00 2026-06-12T19:01:03+00:00

Is there a quicker way to convert the following data into a c style

  • 0

Is there a quicker way to convert the following data into a c style pointer array?

GLfloat verticalLines [] = {
0.59, 0.66, 0.0,    
0.59, -0.14, 0.0
}

My current approach is to manually iterate over the data using the method below:

-(GLfloat *)updateLineVertices{

int totalVertices = 6;
GLfloat *lineVertices =  (GLfloat *)malloc(sizeof(GLfloat) * (totalVertices));

for (int i = 0; i<totalVertices; i++) {
    lineVertices[i] = verticalLines[i];
}

return lineVertices;
}

Some additional info.
Ultimately I will need the data in a format which can be easily manipulated, for example:

-(void)scaleLineAnimation{
GLfloat *lineVertices = [self updateLineVertices];
for (int i = 0; i<totalVertices; i+=3) {
     lineVertices[i+1] += 0.5; //scale y axis
}
}
  • 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-12T19:01:04+00:00Added an answer on June 12, 2026 at 7:01 pm

    It depends on if verticalLines is going to stick around or not. If it’s defined like it is above and it’s not going to change, you can forgo the whole malloc and just point lineVertices to it.

    linesVertices = &verticalLines[0]
    

    if verticalLines is going to change, you probably want your own copy, so you’ve got no choice but to copy the actual data from one part of memory to another as you are doing, that being said, this might be a bit more elegant

    for (int i = 0; i<totalVertices; i++){
        lineVertices[i] = verticalLines[i];
    }
    

    or the preferred method is probably to use memcopy(), here is some working code

    //MemcopyTest.c
    #include <cstdlib>
    #include <stdio.h>
    #include <string.h>
    
    int main(){
       float a[] = {1.0,2.0,3.0};     //Original Array
    
       int size = sizeof(float)*3;      
       float *b = (float*)malloc(size); //Allocate New Array
       memcpy(b, a, size);              //Copy Data
    
       for(int i = 0; i<3; i++){
          printf("%f\n", b[i]);
       }
       free(b);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a quicker way than the following to 'flip' a true or false
Is there a quicker way to do the following? Want to cut down the
Is there a quicker (or better) way to get the [RGBA] color components from
Is there a quicker way of creating a date such as: echo date('Y-m-d', mktime(0,
I'm currently using the following to split a file into words - Is there
Is there an easier/quicker way to get the element added using jQuery append: How
I wonder if there is a quicker way for this: I have my Management
is there a quicker way to maven install say a complete lib folder to
Is there a simple way of finding out the current value of a specified
Is there anyway to get the alt tag to display quicker? Also, I notice

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.