Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site.
Related stories
RAM sticks, known for their chip creep and random failures, are among the more annoying pieces of hardware to pinpoint as the source of a technical issue. Before you start digging around in the tower, it's best to start with a quick and free memory check via Windows. This way, you'll know whether or not it's worth swapping around sticks of RAM to see which one is the dud.
Here's how to get started:
Step 1: Open the Start Menu and type in mdsched.exe, then press enter.
Step 2. A pop-up will appear on your screen, asking how you'd like to go about checking the memory. The first option will restart your machine and check the memory right now, and the second option checks the next time you choose to reboot. Pick the option that best suits your needs.
Step 3: Your computer will load a screen that shows the progress of the check and number of passes it will run on the memory. Watch the memory diagnostic tool for errors. If there are no errors, then it's likely that your RAM is not causing any issues, and it's time to investigate other hardware or software issues.
For other tips on diagnosing memory errors, check out Ed Rhee'sHow to test your RAM in Windows.
Thanks to Tech-Recipes for reminding everyone of this free tool.
Uber versus Lyft: Best tips to save you money when you hail a ride.
Tips to secure your Facebook account: It doesn't take long to make sure your Facebook account is locked down.
The above errors appeared when I tried to run the following program. Can someone explain what is a memory error, and how to overcome this problem? . The program takes strings as input and finds all possible sub strings and creates a set(in a lexicographical order) out of it and it should print the value at the respective index asked by the user otherwise it should print 'Invalid'
Ashwini Chaudhary183k3838 gold badges341341 silver badges395395 bronze badges
sachin irukulasachin irukula3,86144 gold badges1414 silver badges1818 bronze badges
5 Answers
This one here:
seems to be very inefficient and expensive for large strings.
Better do
A buffer object keeps a reference to the original string and start and length attributes. This way, no unnecessary duplication of data occurs.
A string of length
l
has l*l/2
sub strings of average length l/2
, so the memory consumption would roughly be l*l*l/4
. With a buffer, it is much smaller.Note that
buffer()
only exists in 2.x. 3.x has memoryview()
, which is utilized slightly different.Even better would be to compute the indexes and cut out the substring on demand.
glglglglglgl69.5k77 gold badges9999 silver badges169169 bronze badges
If you get an unexpected
MemoryError
and you think you should have plenty of RAM available, it might be because you are using a 32-bit python installation. The easy solution, if you have a 64-bit operating system, is to switch to a 64-bit installation of python.
The issue is that 32-bit python only has access to ~4GB of RAM. This can shrink even further if your operating system is 32-bit, because of the operating system overhead.
You can learn more about why 32-bit operating systems are limited to ~4GB of RAM here: https://superuser.com/questions/372881/is-there-a-technical-reason-why-32-bit-windows-is-limited-to-4gb-of-ram
Community♦
mgoldwassermgoldwasser5,63699 gold badges4343 silver badges7575 bronze badges
A memory error means that your program has ran out of memory. This means that your program somehow creates too many objects.
In your example, you have to look for parts of your algorithm that could be consuming a lot of memory. I suspect that your program is given very long strings as inputs. Therefore,
s[i:j+1]
could be the culprit, since it creates a new list. The first time you use it though, it is not necessary because you don't use the created list. You could try to see if the following helps:To replace the second list creation, you should definitely use a buffer object, as suggested by glglgl.
Also note that since you use
if j >= i:
, you don't need to start your xrange
at 0. You can have:A more radical alternative would be to try to rework your algorithm so that you don't pre-compute all possible sub-strings. Instead, you could simply compute the substring that are asked.
Community♦
RodrigueRodrigue2,92522 gold badges3131 silver badges4343 bronze badges
you could try to create the same script that popups that error, dividing the script into several script by importing from external script. Example, hello.py expect an error Memory error, so i divide hello.py into several scripts h.py e.py ll.py o.py all of them have to get into a folder 'hellohello' into that folder create init.py into init write import h,e,ll,o and then on ide you write import hellohello
joshuajoshua
Rajeev KallurRajeev Kallur