Jump to content

Vars/userfunction Limits To Be Removed

Recommended Posts

I saw that in the todo list just now. I'm working on a vector class which allocates the memory in blocks instead of just a really large contiguous array. Its actually just a multi-dimensional array when you wade through all the pointer action.

At creation, you specify the size of the block and the number of holders for initial blocks you want (At that point, nothing is allocated except the initial array of array pointers). The blocks are allocated when needed and the memory is automatically freed when not needed in an effort to minimize the wasted space. There is no actual upper limit to the number of blocks you can have (aside from simply running out of memory). The only reason you specify an initial number is to prevent reallocation every time you add a new block. Reallocation is quick, though. Only the blocks are move, not every element. A vector of 1000 elements with block sizes of 100 would only move 10 items if it had to realloc to a larger array.

I was almost finished with it when my PC went kaput, so I haven't got to work on it for awhile. I need to add an iterator class as operator[] is unchecked and very dangerous to use. I had an idea on how to implement the iterators, too, which I remember, so I'll hit it soon and finish it up if the iterator idea works okay (The underlying implementation is non-contigous so that's a pain to work with).

I think the class would do well for the function/variable limits. It eliminates the upper limit on these elements, while still providing reasonably quick access and low memory cost. The most wasted memory scenario is HolderCount-1 pointers to blocks + BlockSize-1 wasted pointers to elements (Plus some overhead I may or may not need to make the iterator work safely).

It also doesn't have any memory leaks that I can find. I've created 1,000,000 (1 Million!) elements and both let the destructor destroy them AND called pop() 1 million times to destroy them and I don't see anything leaking.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...