Click here to Skip to main content
15,670,482 members
Please Sign up or sign in to vote.
4.50/5 (4 votes)
My question is very broad and has to do with limits. It has to do with using big numbers, big lists, and usability under those conditions. It has to do with memory size and speed, OS-dependent resources, and algorithm design in order to perhaps overcome some of these limitations. How do you write portable code (yet another complicating factor) that intelligently deals with limits? What are all the possible things that could limit the program and how do you design software around this?

Let's say for example that you had to write a math program that would allow users to view any permutation of a variable number of items. The user would set the number of items, n, and then the interface would allow users to find a permutation at a given index. To get at some deeper issues, let's say each permutation was to behave like a button that needed some graphical drawing and when pressed would perform some action such as printing itself. The feel of the program should be that only the limits of the machine would limit the results.

The program would report the limits to the user, saying something like, "n too high for the memory on this machine," or something smarter sounding, more specific, or more user appropriate. This is kind of the essence of my question since whatever could be reported would be a reflection of what the limits could be. I don't have a very good understanding of what those limits are, nor the severity. Maybe the program would report something like, "This value of n may slow computer performance," and the user could abort if they wanted.

It seems like there are many levels where resources or memory could affect performance. I would like to find the perfect balance in the code design using some tricks but nothing too mind-bending, just reasonable enough that the user wouldn't be limited by arbitrary, programmer-set limits, but code not so complicated that it would be too challenging to write or impossible to understand or maintain in the future.

Right now I'm programming an app in Visual C++ .net. My program froze when I tried to create too many CButtons in a CScrollView. At that point I realized I would have to create an illusion of a list of buttons and just create the current ones in view. Maybe what I should do is just use the same buttons and draw differently to them. Maybe what I should do is make my own buttons form scratch. But it seems like the messaging, drawing, and using Microsoft controls is one of the weaker links in the chain for responsiveness and overcoming limits. I wonder if I should even depart form their scrolling for fear of possible limitations there. Since I want to port to other machines, say phone apps, that seems to open a whole new territory of unknowns along those lines.

The data producing algorithms seem to present a similar problem. I can only make assumtions at this point. Like I would assume that pre-generating all of the data in a certain way, of a certain size, I'd guess on the stack, might allow a faster response time and better usabilty. But then it seems like after a certain point the limits of the machine would warrant generating permutations on the fly, creating them singly, when needed, or maybe using the heap to increase the size of the results, or some combination of the above.

Are there ever situations where you use a lot of memory and it works but then you try something else you run out? Would you try and prevent this in the first place or would you allow it to abort later. It seems like you could recover from this crash well with this example but is it worth it? What should the approach be? What is good design in this case?

I found more questions after an experiment in creating a custom interface for quickly selecting an index with the mouse alone, with a very high maximum index value, using CDialog, OnMouseMove(), OnTimer(), and showing the index by using SetWindowText(). I realized I would need to do some tricky manipulation of the digit columns to get better control over the speed of of my incrementing function.

The point is, I was facing more limits. Apart from the speed of Windows function calling, or whatever you'd call those internal workings, I felt like I couldn't begin to do something like manipulating digit columns until I knew what the biggest number could be. Can one query a machine or operating system for these limits or will the limits have to be hard-coded? Can I take into account the way things may change in the future, say with 128-bit numbers a 100 years from now?

Should I consider long to be the largest number for a good reasonable value? Or can I easily be a little more tricky than that? Can I reasonably use long long? I saw a little bit about BigInt class but I don't know how well it would work for this kind of problem.

The button behavior raises more questions. Part of it has to do with portability since I don't even know things like whether I will be able to use customs fonts or operations such as line drawing. Apart from that I don't even know how to balance drawing resources in the enviroment I already have. I'm guessing with what I have I'd be going in the direction of drawing to a memory bitmap and then drawing the button graphics from that. I'm guessing I'll be generating data on the fly and buffer chunks of data possibilities that would be imminent to viewing in some kind of paging system, trying to stay one step ahead of user actions.

So let's hear it folks. How would should I polish my software so that one can use and abuse the limits of a given machine while balancing performance, keeping it very usable?

One recurring response I've seen online with similar questions is that with such high numbers of controls you should be reconsidering interface design. I hope to avoid getting this response since the whole design of this software is to explore large amount of results, allowing the user to go in as deep as they want without arbitrary limits. Links to articles or hearing what your approach would be would be much appreciated.

1 solution

Mark Russinovich has written a lot of blog posts on pushing the limits.
The latest one is here -[^]
You will find the links to others in that post.
It should be a good read.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900