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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:42:51+00:00 2026-05-26T09:42:51+00:00

When I use realloc in my iOS app, it seems it always increases the

  • 0

When I use realloc in my iOS app, it seems it always increases the memory in my application by a power of 2 instead of what I specify.

This causes some issues when I check the size of the allocation against the size of the objects its storing.

Is this how realloc is designed or is there something I’m doing wrong?

typedef struct {
    GLfloat r;
    GLfloat g;
    GLfloat b;
    GLfloat a;
} Color;

typedef struct {
    int objectID;
    int modelID;
    GLfloat scale;
    GLfloat translation[3];
    GLfloat rotation[3];
    Color color;
    bool render;
} Object;

Object* objects;

objects = realloc(objects, malloc_size(objects) + sizeof(Object));

NSLog(@"objects size = %lu", malloc_size(objects)); //prints 64 instead of 56
  • 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-05-26T09:42:52+00:00Added an answer on May 26, 2026 at 9:42 am

    This is an efficiency measure. The arena used by memory allocation routines usually has a fixed “resolution” such as sixteen bytes. That’s because they tend to give you a (for example) sixteen byte header, followed by enough sixteen-byte chunks to satisfy what you need.

    That way, it only ever has to allocate sixteen byte chunks from the arena, making splitting and rejoining of those chunks easier (at the minor cost of up to fifteen bytes of wastage per allocation).

    But, and this is important, even if you ask for ten bytes and it gives you 1K, you’re still only allowed to use those ten bytes!

    If you want to track what you’ve used against what you’ve asked for, that’s an issue you need to handle. Do not rely on information returned from malloc_size for that.

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

Sidebar

Related Questions

Some time ago a friend of mine told me not to use realloc because
When using realloc is the memory automatically freed? Or is it necessary to use
Its really a post for some advice in terms of the use of realloc,
Why would one use realloc() function to resize an dynamically allocated array rather than
Use case: 3rd party application wants to programatically monitor a text file being generated
use this website a lot but first time posting. My program creates a number
Use case: I've just entered insert mode, and typed some text. Now I want
I want to use the git's malloc and realloc wrappers in my code for
I would like to use OpenBSD's implementation of malloc, realloc and free on my
Are there any guarantees that realloc() will always shrink a buffer in-place?? So that

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.