hi, 

so i decide to go vector of array for my previous problem but i error when i 
try to put an array in a vector:

vector<double*> arrayvec;
int main (int argc, char * const argv[]) {
  double a[10000000];
  arrayvec.push_back(a);
}


gives a error, not enough memory to allocate. but if i dont push it to the 
vector(ie i remove the push_back command) it runs perfectly even if i double 
the amount of the array. anyone know why this happen and how to solve it?

thanks in advance ================================= 
http://www.svnstrk.blogspot.com




________________________________
From: Jos Timanta Tarigan <[email protected]>
To: [email protected]
Sent: Thu, March 18, 2010 10:26:26 PM
Subject: Re: [c-prog] setting the array size later

  
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 <idragos...@gmail. com>
To: c-p...@yahoogroups. com
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]


 


      

[Non-text portions of this message have been removed]

Reply via email to