Access Violation when accessing Dynamic Array

tsbockman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 2 10:14:24 PST 2016


On Saturday, 2 January 2016 at 17:39:42 UTC, Jack wrote:
> So I'll just send the whole file if you don't mind:
>
> http://dpaste.com/11V5BYA (Line 174-183)
>
> The contents of the .txt file is :
> http://dpaste.com/3FVW5QR

I didn't put a lot of effort into trying to actually understand 
what you're doing, but a couple of other issues that jumped out 
at me were:

1) You don't need to use `cmp` to compare strings - this isn't 
Java :)
Just use `==` directly - in D this will compare the strings by 
value, not reference.

(If you actually need to compare by reference, you can use `is` 
or compare the `.ptr` properties.)

2) `if(some_bool == true)` is redundant - just write 
`if(some_bool)`.
Similarly, `if(some_bool == false)` can be shortened to `if(! 
some_bool)`.

3) Currently, there is no reason for `flags` to be an associative 
array; it could be replaced by a simple list of variables:

bool
     keyword = false,
     initialize = false,
     gameObject_init = false,
     movement = false,
     playMusic = false,
     playSound = false;

This would be *much* faster than doing an associative array 
lookup for every single character in `script`.

4) The value type for the string[string] fields symbol, 
symbol_init, and keywords could be changed to custom `enum` 
types, instead of `string`, which would again be much faster.


More information about the Digitalmars-d-learn mailing list