digitalmars.D.learn - Global array
- Paul (8/8) Dec 11 2014 Is there any merit (or folly!) in storing a large array, that
- H. S. Teoh via Digitalmars-d-learn (7/17) Dec 11 2014 [...]
- Paul (8/26) Dec 12 2014 I guess I'm looking for the correct method to create a globally
- H. S. Teoh via Digitalmars-d-learn (11/38) Dec 12 2014 Yeah, putting them in module scope is no different. Except that in D,
Is there any merit (or folly!) in storing a large array, that frequently needs to be accessed globally, within a class like so: public class classMap{ public static int[MAPSIZE][MAPSIZE] map; } Or is there a proper 'D' way to do this? TIA
Dec 11 2014
On Thu, Dec 11, 2014 at 08:56:00PM +0000, Paul via Digitalmars-d-learn wrote:Is there any merit (or folly!) in storing a large array, that frequently needs to be accessed globally, within a class like so: public class classMap{ public static int[MAPSIZE][MAPSIZE] map; } Or is there a proper 'D' way to do this?[...] Why do you need to wrap it inside a class? Why not just put it in module-global scope, since it's public anyway? T -- May you live all the days of your life. -- Jonathan Swift
Dec 11 2014
On Thursday, 11 December 2014 at 21:35:43 UTC, H. S. Teoh via Digitalmars-d-learn wrote:On Thu, Dec 11, 2014 at 08:56:00PM +0000, Paul via Digitalmars-d-learn wrote:I guess I'm looking for the correct method to create a globally accessible bunch of data (basically the program state) with associated functions while trying to provide some measure of safety compared to ordinary global variables. I suppose putting them in the same module with that array in the global namespace is no different.Is there any merit (or folly!) in storing a large array, that frequently needs to be accessed globally, within a class like so: public class classMap{ public static int[MAPSIZE][MAPSIZE] map; } Or is there a proper 'D' way to do this?[...] Why do you need to wrap it inside a class? Why not just put it in module-global scope, since it's public anyway? T
Dec 12 2014
On Fri, Dec 12, 2014 at 03:04:21PM +0000, Paul via Digitalmars-d-learn wrote:On Thursday, 11 December 2014 at 21:35:43 UTC, H. S. Teoh via Digitalmars-d-learn wrote:Yeah, putting them in module scope is no different. Except that in D, this is still not as global as C: the symbol is still restricted to the module it's defined in, so you won't be able to refer to it unless you import the module, and also D "globals" are actually thread-local, so each thread will get a separate copy of it. This makes it less prone to nasty issues like race conditions where one thread is in the middle of writing to it while another thread is reading it. T -- Tell me and I forget. Teach me and I remember. Involve me and I understand. -- Benjamin FranklinOn Thu, Dec 11, 2014 at 08:56:00PM +0000, Paul via Digitalmars-d-learn wrote:I guess I'm looking for the correct method to create a globally accessible bunch of data (basically the program state) with associated functions while trying to provide some measure of safety compared to ordinary global variables. I suppose putting them in the same module with that array in the global namespace is no different.Is there any merit (or folly!) in storing a large array, that frequently needs to be accessed globally, within a class like so: public class classMap{ public static int[MAPSIZE][MAPSIZE] map; } Or is there a proper 'D' way to do this?[...] Why do you need to wrap it inside a class? Why not just put it in module-global scope, since it's public anyway? T
Dec 12 2014