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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:27:47+00:00 2026-05-28T17:27:47+00:00

I’m trying to use stxxl as a backing store to a vector. If I

  • 0

I’m trying to use stxxl as a backing store to a vector. If I do nothing it will automatically allocate 1 gig of disk space and everything works perfectly. However I don’t need that much space allocated and, in fact, I need to gracefully scale from my optimal 512 megs down to a min of 128 megs of storage.

Unfortunately I have stxxl::vector defined in my objective-c class and on instantiation of that class the cxx_constructor function is called which starts up stxxl and allocated a gig whether i like it or not.

Is there any way I can override the cxx_constructor call and add my init in before it goes on to instantiate my class? I did try and create a simple object that would get instantiated by cxx_constructor. Unfortunately, however, for some unknown reason cxx_constructor calls my class’s constructor twice.

Is the only option to add a static to that class preventing it from getting instantiated more than once? This is definitely an option just not very elegant. For one I’d love to know why it gets called twice.

Any info much appreciated!

Edit: Here is the code I wrote.

namespace stxxl
{
    class Config
    {
        float GetFreeDiskspace() 
        {
            float totalSpace = 0.0f;
            float totalFreeSpace = 0.0f;
            NSError *error = nil;  
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
            NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];  

            if (dictionary) {  
                NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];  
                NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
                totalSpace = [fileSystemSizeInBytes floatValue];
                totalFreeSpace = [freeFileSystemSizeInBytes floatValue];
                NSLog(@"Memory Capacity of %f MiB with %f MiB Free memory available.", ((totalSpace/1024.0f)/1024.0f), ((totalFreeSpace/1024.0f)/1024.0f));
            } else {  
                NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %@", [error domain], [error code]);  
            }  

            return totalFreeSpace;
        }
    public:
        Config()
        {

            char cacheFileName[256];
            NSString* pTempDir      = NSTemporaryDirectory();
            strcpy( cacheFileName, [pTempDir UTF8String] );
            strcat( cacheFileName, "/stxxlcache" );

            const uint64_t  kFreeSpace          = (uint64_t)GetFreeDiskspace();

            const uint64_t kMaxCacheSize        = 512*1024*1024;
            const uint64_t kCacheSize           = (kFreeSpace > kMaxCacheSize) ? kMaxCacheSize : kFreeSpace;
            const uint64_t kMinCacheSize        = 2000 * ((1 << 15) >> 1) * sizeof( float );
            stxxl::config* pCfg  = stxxl::config::get_instance();
            pCfg->init( cacheFileName, kCacheSize, false );
        }
    };
};

I then declare it inside my app delegate as follows:

stxxl::Config                       mCallOnceConfig;

Then when I run my application with a breakpoint inside the stxxl::Config constructor the breakpoint gets hit twice. I don’t declare it anywhere else. cxx_constructor calls the constructor twice.

(It also worth noting that I’ve added my own stxxl::config::init function and blanked out the default one)

Edit 2: Placing a static bool around the constructor’s code does sort out the double intialisation and everything works as I’d expect. Its a really rubbish solution though 🙁

  • 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-28T17:27:48+00:00Added an answer on May 28, 2026 at 5:27 pm

    Ok I’ve come up with a fairly elegant solution to my problem. I’ve dropped the whole class instance method and now I define my stxxl setup within the app delegates “+ (void) initialize” function. This ONLY gets called once.

    Hopefully that will save some people some hassle if they suffer similar issues in the future 🙂

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT

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.