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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:11:46+00:00 2026-05-20T06:11:46+00:00

In c, if I wanted an array of floats (for instance) I would just

  • 0

In c, if I wanted an array of floats (for instance) I would just define the fixed size and allocate it, and I could access each element for math operations. However, I want the ability to have my arrays be mutable since they will continually grow in size (as the app is running, and the array could easily surpass 10000+ elements) and the idea of NSMutableArray sounds great. However, (if I understand correctly) it only stores objects, I would have to wrap my numbers in NSNumber, and then put those into the array. That seems like a ridiculous amount of overhead to just store an array of floats (or doubles or integers).

On the other hand, I see that there are flout attributes for Core Data, but I don’t see how I could access this in the same way ( array[index] ). Am I missing something here? Should all heavy-lifting math just be done in fixed-sized c arrays, are there ways of using the foundation classes that I haven’t stumbled upon, or are there ways of accessing core data objects like one would access an array?

  • 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-20T06:11:46+00:00Added an answer on May 20, 2026 at 6:11 am

    you aren’t missing anything here; there’s not a formal objc interface for arrays of c scalar types.

    the simple way (as westsider mentioned) is to use std::vector, and then implement serialization/deserialization using a mechanism such as CF/NS-Data.

    you could wrap std::vector in an objc interface, if you wanted:

    /* MONDoubleArray.h */
    
    /* by using pimpl, i'm assuming you are not building everything as objc++ */
    struct t_MONDoubleArray_data;
    
    @interface MONDoubleArray : NSObject < NSCoding, NSCopying, NSMutableCopying >
    {
        t_MONDoubleArray_data* data;
    }
    
    - (double)doubleAtIndex;
    - (void)setDoubleAtiIndex:(double)index;
    - (NSUInteger)count;
    
    /*...*/
    
    @end
    
    /* MONDoubleArray.mm */
    
    struct t_MONDoubleArray_data {
        std::vector<double> array;
    };
    
    @implementation MONDoubleBuffer
    
    - (id)init
    {
        self = [super init];
        if (0 != self) {
        /* remember your c++ error handling (e.g., handle exceptions here) */
            array = new t_MONDoubleArray_data;
            if (0 == array) {
                [self release];
                return 0;
            }
        }
        return self;
    }
    
    /*...more variants...*/
    
    - (void)dealloc
    {
        delete array;
        [super dealloc];
    }
    
    - (NSData *)dataRepresentationOfDoubleData { /*...*/ }
    - (void)setDoubleDataFromDataRepresentation:(NSData *)data { /*...*/ }
    
    /*...*/
    
    @end
    

    then, you’d have accomplished objc serialization without hassle.

    there’s also a way to use a CF/NS_MutableArray for scalars, using pointer (or narrower) sized entries:

    @interface MONFloatBuffer : NSObject
    {
        NSMutableArray * floats;
    }
    
    @end
    
    @implementation MONFloatBuffer
    
    - (id)init
    {
        self = [super init];
        if (0 != self) {
            CFAllocatorRef allocator = 0; /* default */
            CFIndex capacity = 0; /* resizable */
            /* you could implement some of this, if you wanted */
            const CFArrayCallBacks callBacks = { 0 /* version */ , 0 /* retain */ , 0 /* release */ , 0 /* copyDescription */ , 0 /* equal */ };
            floats = (NSMutableArray*)CFArrayCreateMutable(allocator, capacity, &callBacks);
            // now we can read/write pointer sized values to `floats`,
            // and the values won't be passed to CFRetain/CFRelease.
        }
        return self;
    }
    
    @end
    

    however, that would still fail to properly deserialize itself without customization. so… NSPointerArray would accomplish that more easily… but you still fixed to pointer sized values, so you have to write it yourself. which not terribly hard. the downside is the number of variants you may ultimately end up with.

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

Sidebar

Related Questions

Suppose I have an array of a objects of user defined class. Wanted to
I wanted to generate one fix view using interface builder, but the size of
Just wanted to get an idea for ways (web) developers get round the short
just wanted to gather different ideas and perspectives as to which layer should (and
I wanted to break a css file into an array with PHP. Ex: #selector{
I wanted to shrink the size of a large text file with float values
I have a byte array of size 4 byte[] source = new byte[4]; Now
Wanted to convert <br/> <br/> <br/> <br/> <br/> into <br/>
Wanted to get some consensus around a UI feature I'm working on right now.
I wanted some of those spiffy rounded corners for a web project that I'm

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.