1

Original reason to create struct with 3 byte variables here was that I prefered low memory usage over speed in this particular case. I didn't like the code at the second I was writing it, but I still have to ask. Why this doesn't work?

The same struct with 3 int variables works perfectly. I can put the same data into 1 int by a little bit work to save some memory, that is not what I'm asking. I just wonder what List/struct policy generates this error and how can debugger show two different values for the same variable at the same time? The [0,0,1] are values program uses, while [1,13,0] are values that are supposed to be there.

The problem, struct

public struct s_move_count
{
    public byte move;
    public byte whiteCount;
    public byte blackCount;
}

Variable ssm.moves (on a picture) is of type

List<s_move_count>

This is what debugger watch window shows. I guess it is not important in this case, but I write it anyway. I code in Visual Studio 2015 comunity and program is Windows Phone 8.1 application.

Watch window preview

I guess the problem is in some sort of alignments or something like that. But I didn't find such a situation described on the internet.

hoacin
  • 340
  • 1
  • 2
  • 19
  • 1
    What is the code you are using to generate this? Is it possible that the s_move_count gets mutated in the list? – Jetti Aug 23 '16 at 15:55
  • I declare variable and on the same row I init it."public List moves=new List();" if that is what you asked. What it means struct to get mutated? – hoacin Aug 23 '16 at 16:13
  • mutable structures are easier to get wrong that right; otoh that wouldn't explain why ints work. My best guess is that it is a debugger-bug. Are values also wrong? – TaW Aug 23 '16 at 16:24
  • If I understands your question correctly, mutated means replaced? Yes, First I add struct with counters set to 0. Every time for example "whiteCount" increases, I load the structure from list to 'modifiedStruct', modify the 'modifiedStruct' and then I write ssm.moves[x]='modifiedStruct'. – hoacin Aug 23 '16 at 16:27
  • TaW: Program calculates with wrong values, not only watch window. The [1,13,0] are those that should be there and [0,0,1] are those that program actually uses, as I point on a picture by arrows. – hoacin Aug 23 '16 at 16:34
  • VS2015 originally shipped with a *lot* of debugger bugs, it is crucial to apply the updates. You can always get another opinion with Tools > Options > Debugging > General > tick the "Use Managed Compatibility Mode". That forces the old debugger engine to be used, it is a lot less buggy. – Hans Passant Aug 23 '16 at 17:46
  • @HansPassant, Managed Compatibility Mode doesn't apply to Store Apps so it will make no difference. hoacin, be careful with mutable value types; they can behave in unexpected ways. You can see more details here: http://stackoverflow.com/questions/441309/why-are-mutable-structs-evil – Patrick Nelson - MSFT Aug 25 '16 at 23:25

0 Answers0