Bundle text/gif file in the shared object

P

pankaj.khandelwal

Hi,

How can I bundle a text/gif file in the shared object. Basically I want
to read the content of this text file but I cannot have it seperately
on the disc.

Any clues. ?

Pankaj
 
M

Michael Mair

Hi,

How can I bundle a text/gif file in the shared object. Basically I want
to read the content of this text file but I cannot have it seperately
on the disc.

Any clues. ?

Yes. You are completely on the wrong track when asking that
around here.

Look for a newsgroup or other forum where this is on-topic.
In your place, I would try looking for how E-Mail attachments
work, for example.


Cheers
Michael
 
W

Walter Roberson

:How can I bundle a text/gif file in the shared object. Basically I want
:to read the content of this text file but I cannot have it seperately
:eek:n the disc.

C doesn't know what "shared objects" are, but fortunately for you
that part of your question is irrelevant.

Just write a piece of code that reads the object and generates
from that a C source file containing the data in a usable form.

You could do something simple like having the interface be

extern unsigned char the_shared_file[];
extern size_t size_of_the_shared_file[];

or you could go fancier with making the object static (and
thus visible only in the defining file) and providing accessor
routines, possibly even providing an fread_shared_object routine
that mimics fread() in calling parameters.

To generate the necessary C file, the utility C file would read
the entire file into memory, keeping track of how big it was,
and then could write it out even by something as crude as

printf( "size_t size_of_the_shared_file = %lu\n",
(unsigned long) size_of_object );
printf( "unsigned char the_shared_file[] = {\n" );
for (object_index = 0; object_index < size_of_object; object_index++)
printf( "0x%02x,\n", input_object[object_index] );
printf( "};\n" );

It doesn't matter whether you only output one byte per line or
if you pack the bytes into neat rows of 16 or so -- only the
compiler has to look at the generated file once you've debugged the
generating logic.
 
M

Martin Ambuhl

Hi,

How can I bundle a text/gif file in the shared object. Basically I want
to read the content of this text file but I cannot have it seperately
on the disc.

If you want to bundle a file's content into your code, it is easy enough.

Write a small program that reads the file and outputs something like
char gif[] = "\nnn\mmm"
"\ppp\qqq";
with line lengths you find convenient.
Then incorporate the initialized character array into your program.
 
P

pankaj.khandelwal

This gives me a direction.

However if I keep such initalized character array in my program it will
consume memory whether I use them or not. In case I have lot of images
it may take substantial memory which is not desired. I would like to
initialize them when they are called for the first time in the program
and not always. Since I cannot keep them on disc seperately that is
why I asked if there is a way to bundle these images in the shared
object. ( Something like a zipfile ).

Thanks for your help.
 
M

Martin Ambuhl

This gives me a direction.

However if I keep such initalized character array in my program it will
consume memory whether I use them or not. In case I have lot of images
it may take substantial memory which is not desired. I would like to
initialize them when they are called for the first time in the program
and not always. Since I cannot keep them on disc seperately that is
why I asked if there is a way to bundle these images in the shared
object. ( Something like a zipfile ).

You keep using the term "shared object" which has no inteligible
meaning. If you want to keep them in a disk file, just do it. You gave
the impression that you did *not* want to distribute them separately.
There are plenty of tools which are free and callable from C to compress
and uncompress such things on the fly. And there are plenty of tools to
strip unnecessary information from your executable and compress it with
a small prefix to decompress *that*.

Make up your mind what you really want. Then learn to do a search. Any
reasonable thing you might want to do has readily available free tools
to do it. None of those tools are topical in What you cannot do is store things in the aether. Either these things
will be in a file external to your program or stored in your program.
You don't seem to want either, but some mysterious "shared object" which
is neither distributed nor stored anywhere.
 
W

Walter Roberson

This gives me a direction.

Please quote some context. About every 3rd message these days gives
information on how to do that with google groups.

However if I keep such initalized character array in my program it will
consume memory whether I use them or not. In case I have lot of images
it may take substantial memory which is not desired. I would like to
initialize them when they are called for the first time in the program
and not always. Since I cannot keep them on disc seperately that is
why I asked if there is a way to bundle these images in the shared
object. ( Something like a zipfile ).

You have asked in comp.lang.c which only deals with what can be done
with portable standard C, and the answer in standard C is that all you
have is: code, dynamic memory allocation at runtime (malloc() etc),
and objects of static duration that are initialized by default to zero
at program startup time before any code executes.


Your problem is solvable by using OS-specific extensions in some
operating systems, but that's up to the OS, not up to C.


[OT]
A common UNIX approach is via dlopen(RTLD_LAZY) and dlsym().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top