There is a class. I serialize it through BinaryFormatter in a FileStream . Now the question is, is it possible to use this class directly from a file without deserializing it entirely into memory (well, for example, the class weighs 4 GB, agree that it is expensive)?

UPD:

and how did you imagine it without deserialization? Binary serialization does not provide for partial parsing and reading at all, it is not for that. For complex cases, ORM and different classes with a bunch of fields and lazy loading are usually used.

Will it allow me to work with an object of the type MyClass ?

To be honest, I have little idea.

There is a way to "unbox" from memory, but you still need to think about how to load an object into memory (more precisely, calculate where it is in memory) ... do you mean this? How in with (with ++) what to load bytes into structure?

I don't need to load an object into memory. Only the member that I request should be loaded into memory for transmission.

4 Gb is not a DBMS by accident))) In the case of large objects, they use Memo Mapping, but in this case the object is beaten on the pages and works with the page.

Technically, this is not a DBMS. In fact, it is a huge data set stored in an instance of a class. I really do not want to write all this in a relational database, but I am not familiar with others. It will be very difficult to translate the class schema into the database schema. More precisely, not that it would be difficult, they just will be very different, which means that when expanding the functionality, you will have to solve many compatibility problems, instead of going headlong into logic. I do not like to alter the scheme. If it is one - this is normal, but when another appears, connected with the first one, but with differing possibilities, a headache begins.

UPD2:

Something like this looks like a class (I can’t provide a literal code, but the meaning will be clear, I think):

 [Serializable] public class MyClass { List<MyClass2> List<MyClass3> List<MyClass4> ... } [Serializable] public class MyClass2 { public string Prop1 { get; set; } public int Prop2 { get; set; } public MyClass3 Prop3 { get; set; } ... } ... 
  • one
    You have something wrong with the design. The class should be an abstraction of the essence of the real world, and it is unlikely that such an entity will consist of 4G indivisible data. Break your data into logical sub-objects and work with them separately. - VladD
  • 2
    @iRumba: The semantics of your data, that's what I miss. Because serialization of an object of several gigabytes in size means that everything must be rewritten in a new way, most likely. - VladD
  • Comments are not intended for extended discussion; conversation moved to chat . - PashaPash

1 answer 1

For such tasks it is better to use a database. It is precisely for such cases and is intended. :)

And in order to work was convenient and as with the object of the desired class - use micro-ORM. For example Petapo.

Partially deserialize the file you will not work.

In your case, it may make sense to work with SQLite database if you don’t want to set up a SQL server. Although I do not know what you have there for the data and whether they can be stored in SQLite. Just a guess based on already available information.


I also fully support Vlad in his comments.

MyClass from your example is a DB.

sheets with MyClass2, MyClass3, MyClass4 - explicit database tables.