473,804 Members | 3,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serializing a glib data type

Hi,
I want to serialize a glib data type (an hash), but I don't want to
access directly to the fields of the various structs, since it's an
opaque data type: there is one "more-or-less standard way to do it"
that it's more efficient than read all the fields with the iterator,
saves them on file and successively recreating the hash putting them
once per time?

Thanks in advice.

Aug 19 '07
10 3864
On Aug 19, 8:55 pm, CBFalconer <cbfalco...@yah oo.comwrote:
The 'library' is not defined in the C standard. Unless you post
the C-standard code involved here the question remains off-topic.
Although he's working with the library, he's asking a fairly general
question pertaining to the capabilities of C as a language: whether
it's possible to serialize a structure without knowing the structure
of its fields in a way that will work even if the structure layout is
changed.

In short, the answer is no because fwrite() and fread() only work on
raw bytes, and there's no telling what the internal representations
for the fields present in the structure are, or whether there are any
padding bytes, etc. It seems, however, that the library you're using
provides *a* solution, even if it's not the optimal one. Luckily, if
you're doing file I/O, that's probably the real bottleneck, as opposed
to preparing the data for output and reconstructing it from input.

Aug 20 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3303
by: Aleksei Guzev | last post by:
Imagine one writing a class library CL1 for data storage. He defines classes ‘DataItem’ and ‘DataRecord’ so that the latter contains a collection of the former. And he derives class ‘IntItem’ from ‘DataItem’ public class DataItem { public DataItem() {}
3
4821
by: Daniel C Bastos | last post by:
intro: i have a simple c program that uses gtk (1.2) which in turn uses glib. using the flag -Wall i get no warnings. using -Wall -ansi no warnings. using -Wall -ansi -pedantic I get these warnings In file included from /usr/include/gtk-1.2/gdk/gdktypes.h:33, from /usr/include/gtk-1.2/gdk/gdk.h:31, from /usr/include/gtk-1.2/gtk/gtk.h:31,
10
8320
by: copx | last post by:
I want to save a struct to disk.... as plain text. At the moment I do it with a function that just writes the data using fprintf. I mean like this: fprintf(fp, "%d %d", my_struct.a, my_struct.b) This way I have to write another "serializing" function for every new kind of struct I want to write, though. Is there a way to write functions that can write/read any struct to/from plain text format in a portable way?
2
3525
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: + More ways to contact me __________________________________________________________________
3
3575
by: Tom | last post by:
I am having trouble serializing a color property. Basically, it is not serializing the value. For instance, in the following: <Serializable()> _ Public Class TestColor Private _MyColor As System.Drawing.Color = System.Drawing.Color.Red Public Property MyColor() As System.Drawing.Color Get Return _MyColor
3
6877
by: axr | last post by:
Having trouble with Serilization of objects that contain members which are of type Interface eg public class SomeClass { ISomeInterface1 itf1; ClassType1 ct1; ISomeInterface2 itf2;
1
5688
by: Loic Mahe | last post by:
Hello, I would like to compile GLib as a static library on Windows XP with MinGW if possible. I downloaded GLib and needed librairies, but only the .dll files are included in the zip file. I manage to create a static lib project with CodeBlocks IDE. and I manage to use Glib as a dynamic lib but not as a static one.
1
1789
by: ramasubramanian.rahul | last post by:
hi people.. dont know if this the right forum for this doubt ... so sorry if i am mis-posting... i was looking at the way glib 2.10.3 does export optimization using a list of "to be exposed" function names in a file caleed glib.symbols. this file is used by a perl script to generate a header a .c file ( galias.h and galiasdefs.c). This files essentially enusres default visibility for these functions (using the __attribute__((default))__...
4
4636
by: MN | last post by:
Hi all, I'm learning how to use some Glib-functions for simple linked list. I wrote a small program that prepends 2 data (let's say to integers "1" and "2") in list, display them, count total number of elements and returns index of each element. How to avoid these warnings? warning: passing argument 1 of ‘g_list_nth’ from incompatible pointer type warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘struct GList *’
0
10575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10076
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.