Am i going down the right path?

BlitzMax Forums/BlitzMax Beginners Area/Am i going down the right path?

AramusM(Posted 2006) [#1]
I've been slowly learning bmax and got interested in the opengl tutorials. I've progressed a bit and have decided to look at how I would store my data(vert's, UV's etc) in memory. There seems to be many different approaches from using arrays, banks or Tlist. I'd thought I would try with memalloc, here is what i have at the moment

Type baseVert
     Field x:Float Ptr
     Field y:Float Ptr
     Field z:Float Ptr
     Field VertCount:Int
     
     Function Create:baseVert(numVerts:Int)
     	Local tmpVert:baseVert=New baseVert

     	tmpVert.x=Float Ptr(MemAlloc(NumVerts*4))
     	tmpVert.y=Float Ptr(MemAlloc(NumVerts*4))
     	tmpVert.z=Float Ptr(MemAlloc(NumVerts*4))
     	tmpVert.VertCount = numverts
     	
     	Return tmpVert
     End Function

     Method Delete()
     	MemFree(Byte ptr(x))
     	MemFree(Byte ptr(y))
     	MemFree(Byte ptr(z))
     End Method
EndType

Global a:baseVert

a=baseVert.Create(4)

a.x[0]=1.1
a.x[1]=1.2
a.x[2]=1.3



My question is, are there any pitfalls using this approach people have come across? Any suggestions on better implementation of data storage would be welcome.


Chris C(Posted 2006) [#2]
is that the a* path (sorry couldnt resist!)

seriously I acnt see anything wrong with that off the top of my head, but then I'm fairly lazy and I just modified and added to the milkshape loader in one of the nehe demos

it uses arrays and once I fixed a mem leak seems fast enough for me...