Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 141551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:47:41+00:00 2026-05-11T07:47:41+00:00

I’m writing a straightforward C program on Linux and wish to use an existing

  • 0

I’m writing a straightforward C program on Linux and wish to use an existing library’s API which expects data from a file. I must feed it a file name as a const char*. But i have data, just like content of a file, already sitting in a buffer allocated on the heap. There is plenty of RAM and we want high performance. Wanting to avoid writing a temporary file to disk, what is a good way to feed the data to this API in a way that looks like a file?

Here’s a cheap pretend version of my code:

marvelouslibrary.h:

int marvelousfunction(const char *filename); 

normal-persons-usage.cpp, for which library was originally designed:

#include 'marvelouslibrary.h' int somefunction(char *somefilename) {     return marvelousfunction(somefilename); } 

myprogram.cpp:

#include 'marvelouslibrary.h' int one_of_my_routines()  {     byte* stuff = new byte[1000000];     // fill stuff[] with...stuff!     // stuff[] holds same bytes as might be found in a file      /* magic goes here: make filename referring to stuff[] */     return marvelousfunction( ??? ); } 

To be clear, the marvelouslibrary does not offer any API functions that accept data by pointer; it can only read a file.

I thought of pipes and mkfifo(), but seems meant for communicating between processes. I am no expert at these things. Does a named pipe work okay read and written in the same process? Is this a wise approach?

Or skip being clever, go with plan ‘B’ which is to shuddup and just write a temp file. However, i’d like to learn something new and find out what’s possible in this situation, beside getting high performance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:47:41+00:00Added an answer on May 11, 2026 at 7:47 am

    Given that you likely have a function like:

    char *read_data(const char *fileName) 

    I think you will need to ‘skip being clever, go with plan ‘B’ which is to shuddup and just write a temp file.’

    If you can dig around and find out if the call you are making is calling another function that takes a File * or an int for the file descriptor then you can do something better.

    One thought that does come to mind, can you cahnge your code to write to a memory mapped file instead of to the heap? That way you would have a file on disk already and you would avoid the copying (though it’ll still be on disk) and you can still give the function call the file name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Concerning size, it stores an array of bools as an… May 12, 2026 at 1:09 am
  • Editorial Team
    Editorial Team added an answer If the application is developed by you, i would recommend… May 12, 2026 at 1:09 am
  • Editorial Team
    Editorial Team added an answer Try this: Note: The author's final solution builds upon this… May 12, 2026 at 1:09 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.