Bundle text/gif file in the shared object

Discussion in 'C Programming' started by pankaj.khandelwal@gmail.com, Oct 11, 2005.

  1. Guest

    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
     
    , Oct 11, 2005
    #1
    1. Advertising

  2. Michael Mair Guest

    wrote:
    > 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
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
     
    Michael Mair, Oct 11, 2005
    #2
    1. Advertising

  3. In article <>,
    <> wrote:
    :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.
    --
    University of Calgary researcher Christopher Auld has found that
    milk is the most "rational addiction" amongst the several studied.
     
    Walter Roberson, Oct 11, 2005
    #3
  4. wrote:
    > 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.
     
    Martin Ambuhl, Oct 11, 2005
    #4
  5. Guest

    Re: Bundle text/gif file in the shared object

    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.
     
    , Oct 13, 2005
    #5
  6. Re: Bundle text/gif file in the shared object

    wrote:
    > 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 news:comp.lang.c
    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.
     
    Martin Ambuhl, Oct 13, 2005
    #6
  7. Re: Bundle text/gif file in the shared object

    In article <>,
    <> wrote:
    >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().
    --
    "It is important to remember that when it comes to law, computers
    never make copies, only human beings make copies. Computers are given
    commands, not permission. Only people can be given permission."
    -- Brad Templeton
     
    Walter Roberson, Oct 13, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hb
    Replies:
    6
    Views:
    9,212
  2. Douglass Turner
    Replies:
    2
    Views:
    2,102
    Manfred Bartz
    Sep 4, 2003
  3. John
    Replies:
    0
    Views:
    503
  4. Beauregard T. Shagnasty

    Re: filename.gif or filename.gif.jpg?

    Beauregard T. Shagnasty, May 30, 2008, in forum: HTML
    Replies:
    1
    Views:
    816
    Jonathan N. Little
    May 30, 2008
  5. Bergamot
    Replies:
    0
    Views:
    485
    Bergamot
    May 30, 2008
Loading...

Share This Page