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 8446017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:48:53+00:00 2026-06-10T09:48:53+00:00

Assuming I have a function that fills a buffer with binary data easily, how

  • 0

Assuming I have a function that fills a buffer with binary data easily, how can I make that function return said buffer for further use?

The way I am currently doing it is by having it write the buffer (based off the content-length field from recv) write a temp file, then returning the name of that temp file so I can just read the tmp file into memory.

It would be nice however if I could just return the data directly rather than writing it to a tmp file, and using that. The only problem is if I return the binary data I have no way of knowing what the size of the buffer is (it’s not static) So my question is: is there a method of returning this binary data as well as maybe it’s size, or any way that I can work with it?

Or is my best bet just to stick with using tmp files?

  • 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. Editorial Team
    Editorial Team
    2026-06-10T09:48:55+00:00Added an answer on June 10, 2026 at 9:48 am

    In C you can either use a struct to encapsulate bunch of data items together, and pass that to your function, like:

    /* Describes single I/O buffer */
    struct buf {
        char* data; /* pointer to dynamically allocated memory */
        size_t mem_size; /* allocation size */
        size_t data_len; /* how much data is in the buffer */
        struct buf* next; /* can be used for buffer chaining */
    };
    
    /* Returns 0 on success, -1 on error */
    int read_data( int sockfd, struct buf* pb );
    

    Or use value-return arguments, like:

    /* buffer receives data, len tells buffer length on input, and
     * how much was read on success. */
    int read_data( int sockfd, char* buffer, size_t* len );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this PHP function (using PHP 5.3) that I use to decrypt files,
I have the following Javascript function that should return an array of groups that
Assuming I have a function like this my_method(const vector<const T*> & param); I wonder
Assuming I have a JavaScript function like this... function Object1() { this.var1; this.var2; this.var3;
Assuming I have the following two JQuery functions - The first, which works: $(#myLink_931).click(function
Assuming I have a ASP.NET MVC 3 application that runs in a web farm
Assuming i have a post model with created_at, title, and id. How can i
Assuming I have a comments model and a posts model, What code can I
I have several functions which use jquery that are called across different pages. I'm
I have a join function that operates on STL strings. I want to be

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.