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

  • SEARCH
  • Home
  • 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 8927179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:09:38+00:00 2026-06-15T08:09:38+00:00

Beginner here. Is it possible to get a buffer, for example: char buffer[1024]; And

  • 0

Beginner here. Is it possible to get a buffer, for example:

char buffer[1024];

And split it into smaller chunks of memory (random size depending on user input) using malloc until there’s no more space in the buffer? For example: 1st block = 16, 2nd block = 256, 3rd block = 32, etc.. until I reach 1024. Also I would like to create a structure for every block created. I’m using plain C.

Even though I’m not sure if I can do that, I’ve started something:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
    int x = 0;

    printf("Enter size of block to be allocated: ");
    scanf("%d", &x);
    /*(need to implement): call the following function until there's no more
    space left in the buffer*/
    allocate(x);

    return 0;
}

void *allocate(size_t size)
{
    char buffer[1024];
    char *block;
    /*The following allocates a block with the size of the user input.
    How do I associate it with the buffer?*/
    block = (char *) malloc(size + 1);

    //Creates a structure. How do I create one for every block created?
    typedef struct blk_struct
    {
        int data;
        struct blk_struct *size_blk;
        struct blk_struct *next;
    }blk_struct;
    blk_struct *first;
}

Research I’ve done: Google and SO. Couldn’t find anything on both. Perhaps I’m not searching for the right key words?
Thanks in advance.

  • 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-15T08:09:39+00:00Added an answer on June 15, 2026 at 8:09 am

    Malloc uses its own internal memory management, so it will not sub-allocate from memory that you provide.

    There are a number of malloc implementations available (Google “malloc alternatives”) that provide memory management strategies optimized for various use cases (embedded, multiprocessor, debugging). You may well find an existing solution that addresses the underlying problem you are trying to address with this question.

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

Sidebar

Related Questions

Beginner here trying to get a pipeline working in bash. If somebody can see
Python beginner here. I have a text file that is sorted into columns: fields
I have a question about ocaml, i'm a beginner :-) Here is an example
Beginner here See - http://www.w3schools.com/js/tryit.asp?filename=try_dom_tablerow_cells In this example, when change content is pressed, new
I am a Python beginner who is trying to get multiple random lines for
Possible Duplicate: What is “->” in Objective C? beginner question here. Im looking through
Possible Duplicate: Setters and Getters (Noobie) - iPhone SDK I am a beginner here.
JS beginner here. I need help with a script to place different content in
Python beginner here, I have a list of lists and want to refer to
CodeIgniter beginner here. The base URL of my website is ' http://localhost/routing/ '. //

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.