Re: how can I get a reference of array?

2015-02-05 Thread FG via Digitalmars-d-learn
On 2015-02-05 at 09:58, bearophile wrote: zhmt: Will arr.ptr change in the future? As the array add more members , it need more memroy, then remalloc may be called, the pointer maybe change, then the stored pointer will be invalid. Will this happen? Yes, it can happen. Therefore, don't

Re: how can I get a reference of array?

2015-02-05 Thread zhmt via Digitalmars-d-learn
The behavior of array is more or less unpredictable. If it is always a reference like class , it will be more predictable.

Re: how can I get a reference of array?

2015-02-05 Thread zhmt via Digitalmars-d-learn
Sorry, I misunderstand the meaning of array pointer, it is not equals to arr.ptr. The array pointer meets my need perfectly . Ignore my replies above, Sorry!!!

Re: how can I get a reference of array?

2015-02-05 Thread zhmt via Digitalmars-d-learn
Will arr.ptr change in the future? As the array add more members , it need more memroy, then remalloc may be called, the pointer maybe change, then the stored pointer will be invalid. Will this happen?

Re: how can I get a reference of array?

2015-02-05 Thread bearophile via Digitalmars-d-learn
zhmt: Will arr.ptr change in the future? As the array add more members , it need more memroy, then remalloc may be called, the pointer maybe change, then the stored pointer will be invalid. Will this happen? Yes, it can happen. Bye, bearophile

Re: how can I get a reference of array?

2015-02-05 Thread zhmt via Digitalmars-d-learn
On Thursday, 5 February 2015 at 08:58:47 UTC, bearophile wrote: zhmt: Will arr.ptr change in the future? As the array add more members , it need more memroy, then remalloc may be called, the pointer maybe change, then the stored pointer will be invalid. Will this happen? Yes, it can

Re: how can I get a reference of array?

2015-02-05 Thread Jakob Ovrum via Digitalmars-d-learn
On Thursday, 5 February 2015 at 06:58:09 UTC, Ali Çehreli wrote: On 02/04/2015 10:42 PM, zhmt wrote: Here is a simple code snippet: With this approach, the allocation of `arr` itself is often clumsy and error-prone. In this case it is important to note that `arr` is allocated on the stack

Re: how can I get a reference of array?

2015-02-05 Thread Christof Schardt via Digitalmars-d-learn
Ali Çehreli acehr...@yahoo.com schrieb im Newsbeitrag news:mav4a1$l3a$1...@digitalmars.com... On 02/04/2015 10:42 PM, zhmt wrote: The following article is very informative: http://dlang.org/d-array-article.html Nice and important article. But: How could I have looked this up this myself?

Re: how can I get a reference of array?

2015-02-05 Thread zhmt via Digitalmars-d-learn
On Thursday, 5 February 2015 at 10:12:47 UTC, wrote: On Thursday, 5 February 2015 at 06:58:09 UTC, Ali Çehreli wrote: On 02/04/2015 10:42 PM, zhmt wrote: Here is a simple code snippet: With this approach, the allocation of `arr` itself is often clumsy and error-prone. In this case it is

Re: how can I get a reference of array?

2015-02-05 Thread Ali Çehreli via Digitalmars-d-learn
On 02/05/2015 01:49 AM, Christof Schardt wrote: Ali Çehreli acehr...@yahoo.com schrieb im Newsbeitrag news:mav4a1$l3a$1...@digitalmars.com... On 02/04/2015 10:42 PM, zhmt wrote: The following article is very informative: http://dlang.org/d-array-article.html Nice and important article.

Re: how can I get a reference of array?

2015-02-04 Thread Ali Çehreli via Digitalmars-d-learn
On 02/04/2015 10:42 PM, zhmt wrote: Here is a simple code snippet: class A { public int[] arr; } class B { public int[] arr; } void main() { int[] arr; A a = new A; B b = new B; a.arr = arr; b.arr = arr; arr ~= 1; arr ~= -2; foreach(data;

Re: how can I get a reference of array?

2015-02-04 Thread zhmt via Digitalmars-d-learn
void test(ref int[] arr) { arr ~= 4; } It is something like ref variables. But ref just be used in function declaration.

Re: how can I get a reference of array?

2015-02-04 Thread zhmt via Digitalmars-d-learn
@Ali I know the direction now, I should learn more about the pointers. Thx very much.

how can I get a reference of array?

2015-02-04 Thread zhmt via Digitalmars-d-learn
Here is a simple code snippet: class A { public int[] arr; } class B { public int[] arr; } void main() { int[] arr; A a = new A; B b = new B; a.arr = arr; b.arr = arr; arr ~= 1; arr ~= -2; foreach(data; a.arr)