embed resources in shared lib?

  • Follow


Is there a way to embed resources (like gifs) in a shared library?

I've got a nifty widget library and I want to embed an animated gif
that one widget uses in the library with the object code so I don't
have to go looking for it a runtime.

Thanks,

-bryan

0
Reply bryanwilkerson (4) 6/20/2005 10:20:06 PM

bryanwilkerson@yahoo.com wrote:
> Is there a way to embed resources (like gifs) in a shared library?

> I've got a nifty widget library and I want to embed an animated gif
> that one widget uses in the library with the object code so I don't
> have to go looking for it a runtime.

> Thanks,

Embed it as an array as if it had been read into memory. You can create the
array with something like the following.

hexdump -e '16/1 "%02x," "\n"' </path/to/file> | sed 's/  ,//g'

0
Reply William 6/20/2005 11:45:18 PM


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

bryanwilkerson@yahoo.com writes:

> Is there a way to embed resources (like gifs) in a shared library?
>
> I've got a nifty widget library and I want to embed an animated gif
> that one widget uses in the library with the object code so I don't
> have to go looking for it a runtime.

If you use GTK+, take a look at gdk-pixbuf-csource(1).  This creates a
C file with a GdkPixdata structure in it, which may then be used to e.g.
initialise a GdkPixbuf at runtime.


- -- 
Roger Leigh
                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                Debian GNU/Linux        http://www.debian.org/
                GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQFCt+VGVcFcaSW/uEgRAlCUAJ9PNfefy556dE0g2kubGty7SmkEUACgync6
tjfKIbAVzuifdx+9LodTu2w=
=pxw1
-----END PGP SIGNATURE-----
0
Reply Roger 6/21/2005 10:00:39 AM

Thanks for the tip.  I created a script (below) that will create the
array of data.  The downside to this approach is that the data is
allocated on the global heap and adds to the memory footprint of the
application without any control over it.  Other systems such as .Net
and Java provide a means to read the resources from the library as
needed and only impact memory utilization when they are requested.


# creates a .c file and unsigned char array for the
# binary file passed as an argument.  The array is named
# <input_file> with all periods and spaces replaced
# with underbars

filename=$1
# just get the file name of the path & filename
while [ `expr index "$filename" \/` != 0 ]
do
	filename=`expr match "$filename" '[^\/]*\/\(.*\)'`
done
arrayname=${filename//[\. ]/_}

echo ""
echo "/* created with cbin from file $1 */"
echo "unsigned char $arrayname[] = "
echo "{"

hexdump -e '16/1 "0x%02x," "\n"' $1 | sed 's/0x[ ]*\,//g'

echo "};"
echo "unsigned int ${arrayname}_size = sizeof($arrayname);"
echo ""

0
Reply bryanwilkerson 6/22/2005 4:14:44 AM

bryanwilkerson@yahoo.com writes:

> Thanks for the tip.  I created a script (below) that will create the
> array of data.  The downside to this approach is that the data is
> allocated on the global heap

Global initialized data segment is usually *not* called heap on UNIX.

> and adds to the memory footprint of the
> application without any control over it.  Other systems such as .Net
> and Java provide a means to read the resources from the library as
> needed and only impact memory utilization when they are requested.

Perhaps you should read up on "demand paging". Unless you reference
the data, modern UNIX systems will not page it in.

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
0
Reply Paul 6/22/2005 4:34:18 AM

bryanwilkerson@yahoo.com wrote:
> Is there a way to embed resources (like gifs) in a shared library?

In the shell (or makefile) you use:

   giftopnm yourfile.gif | ppmtoxpm -name yourfile > yourfile.xpm

In your source code you use

   #include "yourfile.xpm"

-- 
mail1dotstofanetdotdk
0
Reply Bjorn 6/22/2005 4:05:41 PM

5 Replies
313 Views

(page loaded in 0.354 seconds)

Similiar Articles:













7/21/2012 6:38:07 AM


Reply: