its a performance sensitive program and im dealing with millions of item. is vector gonna hit hard the performance? ================================= http://www.svnstrk.blogspot.com
________________________________ From: Brett McCoy <[email protected]> To: [email protected] Sent: Thu, March 18, 2010 10:14:57 PM Subject: Re: [c-prog] setting the array size later On Thu, Mar 18, 2010 at 5:07 PM, Jos Timanta Tarigan <jos_t_tarigan@ yahoo.com> wrote: > im having trouble with my code. so i have a set of objects. each of this > object has an array with different size. but i dont know yet the size, so i > put a variable(pointer) like this: > > Vec3* texture; > > then i do some calculation and got the size of the array, so i create an > array based on the size i found:\ > > Vec3 array[size]; > > and pass it to a method > > > object.setTexture( array) > > which is like this: > > void setTexture(Vec3 arr*) { > texture = arr; > resetTexture( ); > } > > but then i got a runtime error saying that i got a bad access. anyone know > how can i pass an array to an object? You're using C++, why not use vector class from STL? They are far more flexible than low-level arrays (and can be resized on the fly) and you don't need to mess around with pointers. http://www.cplusplus.com/reference/stl/vector/ -- Brett ------------ --------- --------- --------- --------- --------- - "In the rhythm of music a secret is hidden; If I were to divulge it, it would overturn the world." -- Jelaleddin Rumi [Non-text portions of this message have been removed]
