开发者

creating datatypes at runtime

I have a scenario where I am given data records at runtime. The datatype o开发者_如何学编程f the cells of the record are variable and only known at runtime. How wil I store these records?

For e.g.,

At runtime, I get record_Info = "char[]","int16","int32" Then I get records = "abc" "2" "30", "def" "3" "40"

how can I store these when I cant initialize their types?


Assuming you want to store them in a file. Store the type information at the beginning of the file(say like a header). There are only a predefined set of types. With the type info available you can have converter functions to convert the data into the respective types and store them as binary data in the file. If you have some upper limit of variable data(char[]), then better store fixed data records in the file. It would be easier to access and modify.

If there is no upper limit on the variable data, then u need to store the variable data in TLV format.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜