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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:55:48+00:00 2026-05-20T11:55:48+00:00

I want to allocate x number of objects from a certain objective-c class in

  • 0

I want to allocate x number of objects from a certain objective-c class in such a way that they are laid out contiguously in memory. The platform is iOS.

The actual problem I want to solve is how to store those x objects in memory such that I can iterate over them with as few cache misses as possible. I was thinking of creating a simple c-style array of objective-c objects, but when I allocate such an object with Obj *obj = [[object alloc] init]; and assign this to an index in my array, I am just storing the pointer, so this obviously does not work.

How can I accomplish this?

EDIT: Some more background: I am trying to apply data-oriented design to my iOS game engine, and I believe that laying out objects in memory this way would give me an easy performance gain (am I wrong?) as my current engine would require minimal adjustments.

  • 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-20T11:55:49+00:00Added an answer on May 20, 2026 at 11:55 am

    If you really want to do this (don’t optimize unless you’re certain you are facing a bottleneck), you would have to override the +allocWithZone: method for your class. I suggest you read Mike Ash’s wonderful recent article Custom Object Allocators in Objective-C. Quoting from it:

    An Objective-C object is just a chunk of memory with the right size, and with the first pointer-sized chunk set to point at the object’s class. A custom allocator thus needs to return a pointer to a properly-sized chunk of memory, with the class filled out appropriately.

    So you could allocate a large amount of memory (with calloc()) first and then your allocWithZone: method could reserve a space in this large chunk of memory at the correct position.

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

Sidebar

Related Questions

I want to add number of images from library to a view. The number
I want to rotate a linked list that contains a number. 123 should be
I want to read from one file that has several kinds of data-types. I
What's the best way to find the number of threads that will be used
I want to allocate rankings to users, based on a points field. Easy enough
Help. TCHAR* b; TCHAR* c=TEXT(qwerty); I want to allocate memory and copy content of
I want to statically allocate the array. Look at the following code, this code
I know that there are functions in the objective-c runtime that allow you to
I want to have a fix length mutable content shared data buffer and that
I'm planning on creating a number class. The purpose is to hold any amount

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.