/usr/share/doc/gtkmm-documentation/tutorial/html/sec-memory-shared-resources.html is in gtkmm-documentation 3.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Shared resources</title>
<link rel="stylesheet" href="style.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Programming with gtkmm 3">
<link rel="up" href="chapter-memory.html" title="Chapter 25. Memory management">
<link rel="prev" href="chapter-memory.html" title="Chapter 25. Memory management">
<link rel="next" href="chapter-builder.html" title="Chapter 26. Glade and Gtk::Builder">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Shared resources</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="chapter-memory.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center">Chapter 25. Memory management</th>
<td width="20%" align="right"> <a accesskey="n" href="chapter-builder.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Shared resources">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-memory-shared-resources"></a>Shared resources</h2></div></div></div>
<p>
Some objects, such as <code class="classname">Gdk::Pixbuf</code>s and
<code class="classname">Pango::Font</code>s, are obtained from a shared store.
Therefore you cannot instantiate your own instances. These classes typically
inherit from <code class="classname">Glib::Object</code>. Rather than requiring you to
reference and unreference these objects, <span class="application">gtkmm</span> uses the
<code class="classname">Glib::RefPtr<></code> smartpointer. Cairomm has its own
smartpointer, <code class="classname">Cairo::RefPtr<></code>.
</p>
<p>
Objects such as <code class="classname">Gdk::Pixbuf</code> can only be instantiated
with a <code class="methodname">create()</code> function. For instance,
</p>
<pre class="programlisting">
Glib::RefPtr<Gdk::Pixbuf> pixbuf = Gdk::Pixbuf::create_from_file(filename);
</pre>
<p>
</p>
<p>
You have no way of getting a bare <code class="classname">Gdk::Pixbuf</code>. In the
example, <code class="varname">pixbuf</code> is a smart pointer, so you can do this, much
like a normal pointer:
</p>
<pre class="programlisting">
int width = 0;
if(pixbuf)
{
width = pixbuf->get_width();
}
</pre>
<p>
</p>
<p>
When <code class="varname">pixbuf</code> goes out of scope an
<code class="methodname">unref()</code> will happen in the background and you don't need
to worry about it anymore. There's no <code class="literal">new</code> so there's no
<code class="literal">delete</code>.
</p>
<p>
If you copy a <code class="classname">RefPtr</code>, for instance
</p>
<pre class="programlisting">
Glib::RefPtr<Gdk::Pixbuf> pixbuf2 = pixbuf;
</pre>
<p>
, or if you pass it as a method argument or a return type, then
<code class="classname">RefPtr</code> will do any necessary referencing to ensure that
the instance will not be destroyed until the last <code class="classname">RefPtr</code>
has gone out of scope.
</p>
<p>See the <a class="link" href="chapter-refptr.html" title="Appendix A. The RefPtr smartpointer">appendix</a> for detailed information about RefPtr.</p>
<p>
If you wish to learn more about smartpointers, you might look in these
books:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
Bjarne Stroustrup, "The C++ Programming Language" - section 14.4.2
</p></li>
<li class="listitem"><p>
Nicolai M. Josuttis, "The C++ Standard Library" - section 4.2
</p></li>
</ul></div>
<p>
</p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="chapter-memory.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"><a accesskey="u" href="chapter-memory.html"><img src="icons/up.png" alt="Up"></a></td>
<td width="40%" align="right"> <a accesskey="n" href="chapter-builder.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter 25. Memory management </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> Chapter 26. Glade and Gtk::Builder</td>
</tr>
</table>
</div>
</body>
</html>
|