Jump to content
Leopard20

Best array position for another array with variable size?

Recommended Posts

Hello everyone.


Let's say I want to place array A inside array B:

B = [....A....]

The dots mean there may be other variables with fixed memory size after or before A (typically some strings or integers in my code).

Array A however, may have a variable size (due to using pushBack/append/deleteAt/set for this array), from 0 all the way up to hundreds of elements.

 

In terms of memory allocation speed, is there any difference where you put A inside B?
Also, does reading speed (B select _index) vary according to where A is? (I think it doesn't, but asking to make sure)

I'm asking this because arrays B and A (and their contents) are read and sometimes modified per frame.

Share this post


Link to post
Share on other sites

I'm not sure what you are trying to accomplish, a code example would be better so I could understand :)

 

Share this post


Link to post
Share on other sites
1 hour ago, gc8 said:

I'm not sure what you are trying to accomplish, a code example would be better so I could understand 🙂

 

It's a general question. No code is needed.

 

I don't think anyone but the devs can answer it. Hopefully @Dedmen or @Dwarden can help!

Share this post


Link to post
Share on other sites
14 hours ago, Leopard20 said:

Hello everyone.


Let's say I want to place array A inside array B:


B = [....A....]

The dots mean there may be other variables with fixed memory size after or before A (typically some strings or integers in my code).

Array A however, may have a variable size (due to using pushBack/append/deleteAt/set for this array), from 0 all the way up to hundreds of elements.

 

In terms of memory allocation speed, is there any difference where you put A inside B?
Also, does reading speed (B select _index) vary according to where A is? (I think it doesn't, but asking to make sure)

I'm asking this because arrays B and A (and their contents) are read and sometimes modified per frame.

Arrays are stored by reference. 

 

As long as you know which index A is stored in the answer is: no, where you put A in the B array has no bearing on the access time or memory allocation time. 

 

In any practical application "array select 0" and "array select n" are equal in speed. 

  • Thanks 1

Share this post


Link to post
Share on other sites
On 4/10/2020 at 7:44 PM, Leopard20 said:

In terms of memory allocation speed, is there any difference where you put A inside B?

no

On 4/10/2020 at 7:44 PM, Leopard20 said:

Also, does reading speed (B select _index) vary according to where A is? (I think it doesn't, but asking to make sure)

no

  • Thanks 1

Share this post


Link to post
Share on other sites
5 hours ago, Dedmen said:

no

no

Good to know! 🙂
Thanks

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×