I think if i change guchar *buffer = 0; to guchar *buffer = "Filename";and then i get the string? length of buffer and apply that value to gint lenit should work. So is g_strv_length the function i use to get the length of buffer?

If you intend to calculate the sums for text buffers, use g_compute_checksum_for_string function, since you can ignore the length parameter if your string is NULL terminated (and most probably will be).

On the other hand, if you'll be calculating sum for some binary data, the length value will probably come with it, since there is no way of determining the size of the binary chunk. (If data will be read from disk, (f)read family of function returns some size indicator.)

Main point of all this is: if you have NULL terminated string, you don't need length parameter; if you're dealing with non-NULL terminated string or binary blob, there is no way to determine the length of the data and that value should be obtained at data creation (read) time.

BTW, g_strv_lenght has nothing to do with string lengths. This function is intended to be used with NULL-terminated arrays of strings (gchar **array or gchar *array[]) and returns number of strings in array.

What i wanted to do was calculate the sum for binary data so i was trying to figure out how GChecksumType worked as you can tell i am kinda clueless on going about doing that. I must have googled for days and read as much source code i could find that used it. My non working example was a best guess as there is virtual zero info on usage.

Thanks for the example code and your response it helped. Ill make up a tutorial and post example code once i solve this problem

What if i wanted to get the sum of say gtk+-2.16.1.tar.gz its 25.7 MB (26924620 bytes) could i just increase the MAX_SIZE or will memory start to be an issue?

The only theoretical limitation on the file length is the gsize's max value (2^32 on 32-bit machines and 2^64 on 64-bit machines). But the practical limitation will probably be the amount of RAM available, since my sample code "slurps" the whole file in at once (and this is the only way of calculating sums with glib).

For larger files you'll have to use some other method of calculation, eg. the one that can calculate sum progressively while reading file in chunks.

So if i use g_checksum_new () and step threw the binary blob with fread while performing g_checksum_update () after every 1meg of data read
and finally calling g_checksum_get_string () i should be able to checksum large files.

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum