Saturday, November 29, 2014

GLib: Transfer Full

While reading the GLib Reference Manual, or any other manuals for glib based libraries such as GObject, Gtk+ or GStreamer, you might notice that some parameters or returns are annotated as Transfer Full. The glib reference manual explains in the annotation glossary as

Free data after the code is done.

What exactly does this mean? This means that all responsibility of the objects that annotated variables point to will be transferred to the other side beyond the API borders.

GObject Introspection Reference Manual or GObject-Introspection Annotations Wiki has a much better description of the annotation, including other modes.

Returns

When a function of the return is annotated, you are the one to control the life of the returned object. You decide when to free() or not. All the responsibility is fully transferred to you after the function returned.

Out Parameters

This is similar to the returns. Everything is transferred to you. Free when you do need them any more.


/* -*- compile-command: "gcc -Wall -Wextra -g $(pkg-config --cflags --libs gio-2.0) transfer-full-out.c" -*- */
#include <gio/gio.h>
#include <stdio.h>

int main()
{
        GFile *file;
        char *buf;
        gsize len;

        file = g_file_new_for_path("/etc/passwd");
        g_file_load_contents(file, NULL, &buf, &len, NULL, NULL);

        fwrite(buf, len, 1, stdout);
        g_free(buf);

        return 0;
}

In Parameters

You pass your data to a function with Transfer full annotation, you are no longer the owner of the object.


/* -*- compile-command: "gcc -Wall -Wextra -g $(pkg-config --cflags --libs gio-2.0) transfer-full-in.c" -*- */
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
        void *buf;
        gsize len;
        GBytes *bytes;

        len = 100;
        buf = malloc(len);
        sprintf(buf, "%s", "hello");
        bytes = g_bytes_new_take(buf, len);

        // It might be a good idea to remove the reference
        // to the buf.  This ensures that we are no longer
        // able to free it by accident.
        buf = NULL;
        len = 0;

        fwrite(g_bytes_get_data(bytes, NULL),
               g_bytes_get_size(bytes),1, stdout);

        // buf will be freed when byts are freed
        g_bytes_unref(bytes);

        return 0;
}

3 comments :

Blockchain Support Number said...

How to Register and Deposit on Blockchain.
Do you want to enter the world of Blockchain? Do you want to register yourself on Blockchain and also want to deposit in it? If you know how to do the whole process then, you can take aid from the professionals who know all the nitty-gritty about the Blockchain world and can help in every possible way. They can be reached by dialing Blockchain customer service phone number 1833-228-1682 anytime as there are no time limitations. You can approach them for attaining finest solutions and remedies.

Blockchain Wallet phone Number
Blockchain Exchange helpline Number
Blockchain Exchange Phone Number
Blockchain Exchange contact number
Blockchain Exchange phone number
Blockchain account problem
Blockchain Logn Failed
Blockchain 2FA Incorrect
Blockchain 2FA Exchange
Blockchain Unable to login
Blockchain Deposit Lost
Blockchain Deposit failed
Blockchain Withdrawal Lost
Blockchain No transaction ID
Blockchain Withdrawal pending
What is a Blockchain account
Blockchain funds not showing
Account restricted Blockchain
Why was my Blockchain account closed
Blockchain your account is incomplete
Blockchain amount not show In account
Blockchain unconfirmed transaction
Blockchain Deposit Withdrawal failed

Emma Williams said...

Are you one of those users who face difficulty while logging in to the Binance account? Instead of worrying about the error, you can always look for the easiest solutions. All you have to do is dial Binance helpdesk number 1833-228-1682 which is the platform to start your conversation with the experts who are skilled in handling the problems and known for delivering spectacular services. Feel free to get in touch with the experts who have gotten solutions and remedies to resolve your error.
Binance Exchange contact number
Binance Exchange phone number
Binance account problem
Binance Logn Failed
Binance 2FA Incorrect
Binance 2FA Exchange
Binance Unable to login
Binance Deposit Lost
Binance Deposit failed
Binance Withdrawal Lost
Binance No transaction ID
Binance Withdrawal pending
What is a Binance account
Binance funds not showing
Account restricted Binance

jones elmer said...

Creatine == > Athletes need to focus in on sports nutrition including what kind of supplements to take if they are to be competitive and on top of their game. They not only need to know the required ratios of organic nutrients such as proteins, carbohydrates and fats but also when to take them. This is especially true of extreme sports in which strength and endurance activities may require above average consumption of nutrients.

Creatine == > I advise the slow load method. I believe the danger of side effects and strain on your detoxing system is not worth the faster results of the quick load. Let's be honest, one month isn't very long to wait anyway. If you've been working out for some time you've in all likelihood realised that getting strong and big is a long process, not measured in weeks or months but in years. Be patient, and do what's best for your long term development.

As with many things in life, the simplest is the best in this case. Plain old Where to buy Creatine, the supplement that has been tested and proven to work for years, will give you the same muscle building benefit as cell tech creatine for pennies per serving.

Creatine == > Try it and see and let us know how that works for you after the doc puts you on an intravenous drip. No, seriously, you need daily feedings of wholesome and complete nutrients.

Creatine == > Over the years, there have been no lack of arguments on what is the best diet for peak athletic performance. Dietitians the world over have various opinions on what the athlete should eat in order to perform at their best levels. No doubt, these arguments will continue to exist for many more years to come.

Creatine == > There was a time when I too was unable to get the gains that I was after. After much experimenting with my own body I was finally able to find something that really worked to help me build muscle.

Creatine == > Drink plenty of water per day, but just keep in mind, there can be too much of a good thing. Being properly hydrated is necessary for optimum performance in the gym and for keeping your body performing well.



creatine
where to buy creatine
creatine powder
creatine muscle builder
https://creatine.wheretobuyy.com/