Sign in to follow this  
vbuser1338

Malloc Question

Recommended Posts

vbuser1338    175
I read the post below and I didn't see an answer that worked. I want to declare a Sector for a OpenGl project. And it has to have an array of Triangles in it which is another structure. But I want to make the array of triangles the size that I load from the file. So I was going to use
sector1.triangle = new TRIANGLE[numtriangles];
but You can't use new in Cocoa on mac. triangle in the Sector is a Pointer to the structure Triangles. So how would I make say I load the number 36 make sector1.triangle[36] using maloc? Thanks vbuser

Share this post


Link to post
Share on other sites
vbuser1338    175
Ya I tried that but I got this error.

*** malloc: vm_allocate(size=3021615104) failed (error code=3)
*** malloc[1376]: error: Can't allocate region


any ideas
Thanks vbuser

Share this post


Link to post
Share on other sites
Mercury    776
Quote:
Original post by vbuser1338
*** malloc: vm_allocate(size=3021615104) failed (error code=3)

3021615104 is the size you're trying to allocate in bytes, it seems. I don't think so, that's a hell of a lot of RAM. Your numtriangles value is wrong.

Share this post


Link to post
Share on other sites
Palidine    1315
It looks like you are asking it to malloc 3GB of memory. Do you have that much memory on your computer? if not, then you have too many TRIANGLES, or as mentioned above, numTriangles is wrong.

-me

Share this post


Link to post
Share on other sites
Phillip Martin    226
It seems to be trying to allocate 3gig of data, and, well, thats rather huge.

Either sizeof(TRIANGLE) is insanely large, or numtriangles is insanely large.

What is sizeof(TRIANGLE) and numtriangles supposed to be?

Share this post


Link to post
Share on other sites
vbuser1338    175
Ya I'm stupid when I went to load the num triangles I was going to a point in the file that didn't exist . I was trying to get the number after numPolygons and In my file it is numTriangles so It was putting a weird number into numtriangles. Another stupid mistake. But thanks for the help.
vbuser

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this