c# - Binary serialization, IFormatter: use a new one each time or store one in a field? -
using binary formatting 1st time in .net c#
code msdn this:
iformatter formatter = new binaryformatter(); stream stream = new filestream("myfile.lvl", filemode.create, fileaccess.write,fileshare.none); formatter.serialize(stream, globals.currentlevel); stream.close();
just wondering should store iformatter
in field in class , use on , on again or should above , instantiate new 1 every time save/load something?
i noticed not idisposable
.
there's little overhead in re-creating binaryformatter
, of properties sets in constructor enum
s, see here (thanks reflector):
public binaryformatter() { this.m_typeformat = formattertypestyle.typesalways; this.m_securitylevel = typefilterlevel.full; this.m_surrogates = null; this.m_context = new streamingcontext(streamingcontextstates.all); }
if going re-use though, you'd need synchronize access serialize
, deserialize
methods keep them thread-safe.
Comments
Post a Comment