如何将具有字符指针的 C 结构插入 DBD 文件
我正在将我制作的文件系统更改为 DBD。
我没有选择转换具有字符点成员的结构 将这些结构插入 DBD 文件中
例如, , 如果有如下结构,
typedef struct
{
int IndexKey;
int groupID;
char* name;
char* pNum;
char* pAddr;
char* pMemo;
} TsomeRec;
我做了一个要转换的结构,如下所示
typedef struct
{
int IndexKey;
int groupID;
char name[MAX_NAME_LEN];
char pNum[MAX_NUM_LEN];
char pAddr[MAX_ADDR_LEN];
char pMemo[MAX_MEMO_LEN];
} TsomeRec2;
但是,要转换的结构太多了。
因此,考虑到性能,我正在寻找将这些结构插入 DBD 文件的最有效方法。
坦白说,我并不熟练。 请尽可能具体地描述。
谢谢~
I am changing from a file system I made into DBD.
And I had no choice to convert structures that have character point members
to insert these structures into the DBD file
for examble,
If there is a structure as below
typedef struct
{
int IndexKey;
int groupID;
char* name;
char* pNum;
char* pAddr;
char* pMemo;
} TsomeRec;
I made a structure to convert as below
typedef struct
{
int IndexKey;
int groupID;
char name[MAX_NAME_LEN];
char pNum[MAX_NUM_LEN];
char pAddr[MAX_ADDR_LEN];
char pMemo[MAX_MEMO_LEN];
} TsomeRec2;
But, there are too many structures to convert.
So, I am seeking for the most efficient way to insert these structures into DBD files, considering Performance.
Frankly speaking, I'am not proficient.
please describe as specific as possible.
Thank you~
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你想插入以下结构:
然后,使用 'p' 将你的键/数据存储到 BDB 中,并使用 free(p)
读取、返回数据、读取字符串的大小、malloc 所需的内存并读取字符串本身
if you want to insert the following structure:
then, use 'p' to store your key/data into BDB and free(p)
to read, the data back, read the size of the string, malloc the required memory and read the string itself
我认为您可以尝试为您的结构设置默认值
或在您的结构中进行枚举
希望这会有所帮助
I think you can try setting default values for you structure
or making enumeration into your structure
hopefully this helps
您的数据需要可序列化。您在问题中的一个案例中已经做到了这一点。
对于精通 C++ 和 BDB 的人来说,以通用方式对多种类型的记录执行此操作是一项任务(我之前已经完成过)。你似乎表明你不熟练。所以如果你想自己做,你就必须转换每个结构,听起来很单调(你说太多了),但至少需要较少的技巧。
您正在寻找的解决方案太复杂,无法生成,而且太长,无法在此处发布。
Your data needs to made serializable. You have done that in one case in your Question.
To do this in a general way for many types of records is a task for somebody proficient in C++ and BDB (I have done it before). You seemed to indicate you were not proficient. So if you want to do it yourself you will have to convert each structure which sounds monotonous (you said there were too many), but at least it requires less skill.
The solution you are looking for is too complex to produce and too long to post up here.