How to solve memory problem [closed] - visual-c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
We have created an application which consumes too much physical memory on mouse click or screen touch. The code of the application is of thousands of lines and is developed in C++.
So far our approach is to free the memory is to minimize the application. But this approach have consequences. So we are looking for alternative way to solve the problem. This application runs on full screen mode.

You're in an difficult position - discovering this kind of problem in a late stage of development is unfortunate. It's quite likely that fundamental redesign is needed.
I infer that some particular code path, in response to a user event, is very hungry for memory. You need to understand exactly what's happening and how best to improve things. We can't help with that without far more details. But an example I've seen in the past: are you grabbing a whole load of data from some database and keeping it all in memory? Do you really need all that data all the time. can you offload more of the query to the database?
You also need to look at what "too much" memory means. Are you targeting too small a machine? Perhaps just splashing out a few tens of pounds on more memory is cheaper than spending many developer days squeezing a quart into a pint pot?
Edited in response to comment:
OK then this does sound like a leak. You should be able to identify the places where you allocate memory, presumably there should be some kind of symmetry, where there are paired frees. I would start by just identifying the allocations, something is gabbing 2MB, should be possible to find it. Then understand when that memory should be released, for example once a screen has been displayed, or when a user session ends. Then find out why it's not happening. You may need to look at your overall strategy for memory management. Smart pointers? Some kind of manager with a house keeping thread? Overall you need a clear design philosophy to resource acquisition and release. This is hard to retrofit to an existing app, so you have my sympathy.

Related

why linux instead of windows because of ram? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm trying to migrate an application from linux to Win and already I'm having a lot of difficulties with heap size, ram and ...
what is it about Ram that most people prefer to work on linux instead of Win?
The only reason I know of is: you have a bug in your original code.
There are two main differences in managing memory:
1) Linear
Under Unix systems, you grow your heap as required and the addresses are therefore allocated linearly, increasing from the end of your data segment up. In most cases that is transparent. However, if you do reinterpret_cast<>() (or C-like casting) between pointers and integers, you may have problems there too (if you went from Linux 32 to Windows 64, for example.)
2) Clear
Windows clear the RAM (set it to all zeroes) in a different way than Linux. That's in most cases what causes grieves as you describe. This also applies to stack data.
In debug mode, also, Windows debug libraries, on purpose, set the RAM to different values (such as 0xCC or 0xFE). This is useful to detect bugs and it could very well be that you have bugs in your Linux version, only it "works" just because.
Also in regard to the stack, because the cl and gcc compilers do it completely differently, the stack is completely different. So the only thing you're seeing is that you have a bug in your original code...

Is code clone a common practice in C,Java and Python? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Code clones, also known as Duplicate code is often considered harmful to the system quality.
I'm wondering whether these duplicate code could be seen in standard APIs or other mature tools.
If it is indeed the case, then which language(such like C,Java,Python,common lisp etc.) do you think should introduce code clone practice with a higher probability?
Code cloning is extremely common no matter what programming language is used, yes, even in C, Python and Java.
People do it because it makes them efficient in the short term; they're doing code reuse. Its arguably bad, because it causes group inefficiencies in the long term: clones reuse code bugs and assumptions, and when those are discovered and need to be fixed, all the code clones need to be fixed, and the programmer doing the fixing doesn't know where the clones are, or even if there are any.
I don't think clones are bad, because of the code reuse effect. I think what is bad is not managing them.
To help with the latter problem, I build clone detectors (see our CloneDR) that automatically find exact and near-miss duplicated code, using the structure of the programming language to guide the search. CloneDR works for a wide variety of programming languages (including OP's set).
In any software system of 100K SLOC or more, at least 10% of the code is cloned. (OK, OK, Sun's JDK is built by an exceptionally good team, they have only about 9.5%). It tends to be worse in older conventional applications; I suspect because the programmers clone more code out of self defense.
(I have seen applications in which the clones comprise 50%+ of code, yes, those programs tend be awful for many reasons, not just cloning).
You can see clone reports at the link for applications in several langauges, look at the statistics, and see what the clones look like.
All code is the same, regardless of who writes it. Any API that you cite was written by human beings, who made decisions along the way. I haven't seen the perfect API yet - all of them get to redo things in hindsight.
Cloning code flies in the face of DRY, so of course it's recommended that you not do it. It's harmful because more code means more bugs, and duplication means you'll have to remember to fix them in all the clones.
But every rule has its exceptions. I'm sure everyone can think of a circumstance in which they did something that "best practices" and dogma would say they shouldn't, but they did it anyway. Time and other constraints don't always allow you to be perfect.
Suggesting that permission needs to be granted to allow such a thing is ludicrous to me. Be as DRY as you can. If you end up violating it, understand why you did it and remember to go back and fix it if you get a chance.

Haskell Trading engine [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
so we're doing this assignment at Uni and i have a serious craving to do the assignment in haskell. Its a simulation of a stock trading engine. Situation is that we have data coming in from a csv and we wish to parse each record and process it in a certain way dependent on which market phase its allocated to. Justification for using haskell, is that i view the trading engine as heavy functional system.
I have had haskell experience before but only minor experience, never anything this big.
We were wanting to run a thread which would import the csvs into a queue of unprocessed orders and then have the main program access this queue for processing each order. However how could i achieve this? I know in C# i would just set up the class so it could access the CSVParser class that would hold the unprocessed queue. This also means that the import thread would be continuously running through all the market phases or until it finished importing the csv file.
Any guidance on how to achieve this would be great! (not looking for a fully typed script, just what things in haskell i would need to look at)
It's not clear what you're asking for.
To start a new thread, use forkIO from Control.Concurrent.
To queue data from one thread to another, you may be interested in Chan from Control.Concurrent.Chan. Other Control.Concurrent.* abstractions are available (there's also the stm package if you find yourself needing something more heavy duty).
For parsing CSV, search the Hackage package list for “CSV”; I haven't used Haskell to parse CSV, so I can't advise on which one to use.

What can't I just set everything as static? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I was just wondering why I can not just set everything as static? I think if I set something as a static then it has a better access time than other variables that haven't set as static..
But I assume there might be a problem and that is the reason why people are not doing this.. What are the problem could be? Thanks in advance..
Consider a class Person and all your friends are instances of that class. Now consider they all have names, their names are their attributes.
Now, if that name attribute was static, all friends would have the same name.
That's why we have instance variables too.
If you make everything static, then there only exists a single copy of it in the entire program. This can be a problem when you want multiple computations of the same thing to go on in parallel or if you want to track multiple copies of the same logical object at the same time.
As for the access time, one should consider correctness first and foremost, then optimize later. Additionally, optimizations should be based on actual measurements, not speculation. If you actually measure how long things are taking, that is pretty much never going to be the optimization you make.

Am I the only one who makes spelling and grammar mistakes when programming? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 13 years ago.
I don't know if I am a bad programmer because I often make mistakes when outputting information on a site, things like "thanx for subscribing to our service" instead of "Thanks for subscribing to our service".
I think this is because I usually don't concentrate on the spelling, my main focus is to get the functionality running perfectly. Please give me your opinion, do you concentrate on the spellings or the functionality?
If I'm writing a message which will be visible to users, I'll make sure it's clear and correct. If I'm writing a message which will only be visible to other developers, I'm slightly less careful - in particular, typos aren't really a problem, so long as I express myself clearly.
Fortunately my spelling/typing/grammar is reasonably good anyway, so I don't need to think too hard about this, but I think it is important for customer-facing text.
Developers often aren't very good at writing messages for users. It can be hard to put yourself in the position of someone who really has no idea about what's going on in the background: they just want to get their email (or whatever it is) working. If you're lucky, you may be able to get a technical writer to help compose appropriate text.
IMO attention must be paid to both. Cool logic and reliability are no excuse for crappy texts.
You could separate checking the resource from changing the source. When you do changes first change the code, test everything, then proofread the resources.
The CTO at my last job was dyslexic, and a completely brilliant programmer and manager. Every now and then I would go and make a spelling correction to one of his method or variable names (C# handles the refactoring pretty well) and it didn't really matter that much.
When there's user interface work it's much more important to spell things correctly coz it looks very shabby to have a misspelled UI.

Resources