Bin file object database, direct storage object to do database, small project it must be right.

Source: Internet
Author: User

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.IO;6 usingSystem.Runtime.Serialization.Formatters.Binary;7 8 namespaceMscharthelp9 {Ten     Static classfileserialize One     { A         //you can take the array directly when you get the file -          Public StaticT getfileinfo<t> (stringFilePath)whereT:New() -         { theT t =NewT (); -Createfile<t>(FilePath); -FileStream fs =NewFileStream (FilePath, FileMode.Open); -BinaryFormatter BF =NewBinaryFormatter (); +             if(FS. Length <1) {returnt;} -t =(T) (BF. Deserialize (FS));  + FS. Close ();  A             returnT; at         } -  -        //whether the bin file exists -         Private Static voidCreatefile<t> (stringFilePath)whereT:New() -         { -T t =NewT (); in             if(!file.exists (filePath)) -             { toFileStream fs =NewFileStream (FilePath, filemode.create); +BinaryFormatter bs =NewBinaryFormatter (); - BS. Serialize (FS, t); the FS. Close (); *             } $         }Panax Notoginseng  -        //Save Array list<u> the          Public Static voidSave<u> (stringFilePath, list<u>South ) +         { AList<u> Soutrim = (list<u>) south; theFileStream fs =NewFileStream (FilePath, filemode.create); +BinaryFormatter BFF =NewBinaryFormatter (); -             Try $             { $ BFF. Serialize (FS, Soutrim); -             } -             Catch(Exception) the             { - Wuyi                 Throw; the             } -             finally Wu             { -  About FS. Close (); $             } -         } -  -  A          Public Static voidSave<t> (stringFilePath, T South) +         {   theFileStream fs =NewFileStream (FilePath, filemode.create); -BinaryFormatter BFF =NewBinaryFormatter (); $             Try the             { the BFF. Serialize (FS, south); the             } the             Catch(Exception) -             { in  the                 Throw; the             } About             finally the             { the  the FS. Close (); +             } -         } the     }Bayi}
View Code

Disadvantages

1. If there are 10w records, modify one you need to rewrite the bin file, the cost is quite large, and if you just query a record you also need to re-load the bin all the content into memory to establish the corresponding object.


2.Access, SQL Server can simply understand to do 2 things, first he provides a unified interface, any language any process through SQL can communicate with it, get data.

The second thing he provides is an indexing mechanism that allows you to locate query results based on SQL by not having to load all the data into memory.

3. Modify the object structure will cause the data can not be read, need to keep the original object and the new object, the original data read to the original object, and then through the program to the new object, the new object is saved in a new file (bin), the last original object file and the original data file (BIN) deleted.

4. Real-time saving, not recommended to save in real-time, and so on all processing delay save data best.

But if your application is small, memory is enough to hold the data, and does not need to be saved in real time, then this method is feasible and can be said to be better than access, hehe.

Specific problem specific analysis, suitable for good.

Bin file object database, direct storage object to do database, small project it must be right.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.