Access Violation when accessing Dynamic Array

Jack via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 2 19:41:12 PST 2016


On Saturday, 2 January 2016 at 18:14:24 UTC, tsbockman wrote:
> 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.)

I didn't actually knew it works that way because last time I 
tried using '==' directly it won't compare.

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

Yeah I did that in a panic attempt to fix the problem.

> 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`.

I always thought that associative arrays are much more faster and 
more clean than this. Thanks I'll keep that in mind

> 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.

And this is news to me too. I'll keep enums in mind.

Overall thank you for your help and advice. I'll seriously keep 
these in mind.


More information about the Digitalmars-d-learn mailing list