Persistent Dictionary array support

Jan 2, 2011 at 6:52 AM

Hi,

I can understand why objects are not supported,  but can someone please explain why arrays are not supported as value types in the dictionary??

 

Cheers

Sam

Jan 5, 2011 at 5:28 AM

It was done because having mutable values gives slightly different behaviour from a normal dictionary:

var x = new byte[10];
d["key"] = x;
x[2] = (byte)0x5;

With a persistent dictionary the updated value won't be present, but with a conventional dictionary it will. I wanted the PersistentDictionary to have the exact same semantics as an ordinary dictionary (or fail to initialize).

Several other people have asked about this, so I've come to the conclusion that I was wrong and supporting mutable values is the right thing to do. I'll be adding that support.

 

is that having mutable values gives slightly different behaviour from a normal dictionary:

var x = new byte[10];
d["key"] = x;
x[2] = (byte)0x5;

With a persistent dictionary the updated value won't be present, but with a conventional dictionary it will. I wanted the PersistentDictionary to have the exact same semantics as an ordinary dictionary (or fail to initialize).
Feb 28, 2011 at 8:10 PM

Do you have a timeline on this? I understand the risks, but the current restriction is very inconvenient.

Mar 3, 2011 at 9:36 PM

I've left Microsoft so I won't be contributing code to this project any more. Hopefully one of the other Esent team members will reply.

May 5, 2011 at 3:12 PM
laurionb wrote:

It was done because having mutable values gives slightly different behaviour from a normal dictionary:

var x = new byte[10];
d["key"] = x;
x[2] = (byte)0x5;

With a persistent dictionary the updated value won't be present, but with a conventional dictionary it will. I wanted the PersistentDictionary to have the exact same semantics as an ordinary dictionary (or fail to initialize). 

Several other people have asked about this, so I've come to the conclusion that I was wrong and supporting mutable values is the right thing to do. I'll be adding that support.

is that having mutable values gives slightly different behaviour from a normal dictionary:

var x = new byte[10];
d["key"] = x;
x[2] = (byte)0x5;

With a persistent dictionary the updated value won't be present, but with a conventional dictionary it will. I wanted the PersistentDictionary to have the exact same semantics as an ordinary dictionary (or fail to initialize).

Quick question: how did you plan to monitor (in this case) the byte[] to check for modifications? Can you explain what you had in mind? I'm working on another persistent db and would like to know your approach as I have the same problem (I solved it somewhat, but using a hack: When you read the property from the persistent object AND that property implements ICollection, I automatically mark the object as dirty. The problem with that is that marks the object as dirty even if the collection was not modified).

May 5, 2011 at 9:38 PM

>>CheloXLQuick question: how did you plan to monitor (in this case) the byte[] to check for modifications?

That is not going to be possible, user must know he/she is dealing with a database and not memory storage.
If you modify it you must update the database.

Best regards,
Paul. 

May 5, 2011 at 10:44 PM

Ok, yes, that's what I thought. Just wanted to know if there were some "magical" approach, since my persistent db right now is totally transparent and you never need to save anything (only when dealing with collections/properties of mutable types assigned to the PO)

Regards,