Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 03, 2008 How to easy set size of multi dimentional dynamic array? | ||||
---|---|---|---|---|
| ||||
How to easy set size of multi dimentional dynamic array? for example: class Foo{ private double[][] m_array; this(uint o_length, uint o_width){ // hard way: this.m_data.length = o_length; for(uint i = 0; i < this.m_array.length; i++){ this.m_array[i] = new double[o_width]; } } } |
September 03, 2008 Re: How to easy set size of multi dimentional dynamic array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zarathustra | On Wed, 03 Sep 2008 13:45:12 +0400, Zarathustra <adam.chrapkowski@gmail.com> wrote:
> How to easy set size of multi dimentional dynamic array?
>
> for example:
> class Foo{
> private double[][] m_array;
>
> this(uint o_length, uint o_width){
> // hard way:
> this.m_data.length = o_length;
> for(uint i = 0; i < this.m_array.length; i++){
> this.m_array[i] = new double[o_width];
> }
> }
> }
Try this:
this(uint o_length, uint o_width){
m_array = new double[][](o_length, o_width);
}
|
September 03, 2008 Re: How to easy set size of multi dimentional dynamic array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | Denis Koroskin Wrote:
> On Wed, 03 Sep 2008 13:45:12 +0400, Zarathustra <adam.chrapkowski@gmail.com> wrote:
>
> > How to easy set size of multi dimentional dynamic array?
> >
> > for example:
> > class Foo{
> > private double[][] m_array;
> >
> > this(uint o_length, uint o_width){
> > // hard way:
> > this.m_data.length = o_length;
> > for(uint i = 0; i < this.m_array.length; i++){
> > this.m_array[i] = new double[o_width];
> > }
> > }
> > }
>
>
> Try this:
>
> this(uint o_length, uint o_width){
> m_array = new double[][](o_length, o_width);
> }
Great, ;)
Thanks Denis
|
September 06, 2008 Re: How to easy set size of multi dimentional dynamic array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zarathustra | On 2008-09-03 13:28:47 +0200, Zarathustra <adam.chrapkowski@gmail.com> said: > Denis Koroskin Wrote: > >> On Wed, 03 Sep 2008 13:45:12 +0400, Zarathustra >> <adam.chrapkowski@gmail.com> wrote: >> >>> How to easy set size of multi dimentional dynamic array? >>> >>> for example: >>> class Foo{ >>> private double[][] m_array; >>> >>> this(uint o_length, uint o_width){ >>> // hard way: >>> this.m_data.length = o_length; >>> for(uint i = 0; i < this.m_array.length; i++){ >>> this.m_array[i] = new double[o_width]; >>> } >>> } >>> } >> >> >> Try this: >> >> this(uint o_length, uint o_width){ >> m_array = new double[][](o_length, o_width); >> } > > Great, ;) > Thanks Denis please not that a multidimensional array does not need to be square, so it uses a lot of emory more. You might be interested at my multidimensional array library (tango only for the moment). See http://github.com/fawzi/narray/tree/master/INSTALL.txt ciao Fawzi |
Copyright © 1999-2021 by the D Language Foundation