Allegro.cc - Online Community

Allegro.cc Forums » Allegro.cc Comments » Thread locks too soon

This thread is locked; no one can reply to it. rss feed Print
Thread locks too soon
bamccaig
Member #7,536
July 2006
avatar

In my experience, a small SSD becomes a bit of a bother though (when you inevitably start to run out of space on it) so consider investing in something at least 256 GB IMO. It won't be as cheap, but it should be twice as useful. :)

Append:

I finally figured out the main cause of memory leaks in my "falling block" clone. ::)

diff --git a/main.c b/main.c
index 1d24935..b02a1ae 100644
--- a/main.c
+++ b/main.c
@@ -323,8 +323,10 @@ static void apply_movements(GAME_STATE * S) {
         LINKED_LIST * collisions = NULL;
 
         if(!detect_collisions(S, piece, &collisions) || collisions) {
-            while(collisions != NULL) {
-                COLLISION * collision = collisions->data;
+            LINKED_LIST * it = collisions;
+
+            while(it != NULL) {
+                COLLISION * collision = it->data;
 
                 print_collision(collision);
 
@@ -334,7 +336,7 @@ static void apply_movements(GAME_STATE * S) {
                     S->respawn = 1;
                 }
 
-                collisions = collisions->next;
+                it = it->next;
             }
 
             list_destroy(&collisions,

I was iterating over my collisions list to print them out (diagnostics) and to check if a new piece needs to respawn. The result is that by the time I got around to list_destroy() to free up the memory, the pointer was pointing to NULL because it was the end of the list... ::) By using an iterator variable to step through the list that problem is solved and both the list and the collisions in the list get cleaned up properly.

However, I still have some leaks reported by valgrind.

 HEAP SUMMARY:
     in use at exit: 229,801 bytes in 1,958 blocks
   total heap usage: 44,855 allocs, 42,897 frees, 18,449,114 bytes allocated

 9 bytes in 1 blocks are definitely lost in loss record 7 of 1,522
    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x5F0DC17: _XlcDefaultMapModifiers (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
    by 0x5F0DFE5: XSetLocaleModifiers (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
    by 0x50F0DCF: x_keyboard_init (xkeyboard.c:760)
    by 0x50F0DCF: xkeybd_init_keyboard (xkeyboard.c:929)
    by 0x50AD3E9: al_install_keyboard (keybdnu.c:129)
    by 0x402D10: initialize (in /mnt/data/home/bambams/src/tetrist/game)
    by 0x401919: main (in /mnt/data/home/bambams/src/tetrist/game)

 32 bytes in 1 blocks are definitely lost in loss record 487 of 1,522
    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x5739889: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
    by 0x50EFF09: _al_xglx_config_create_context (xglx_config.c:570)
    by 0x50EC41C: xdpy_create_display_locked (xdisplay.c:438)
    by 0x50ECBF2: xdpy_create_display (xdisplay.c:583)
    by 0x50A67D4: al_create_display (display.c:53)
    by 0x402D30: initialize (in /mnt/data/home/bambams/src/tetrist/game)
    by 0x401919: main (in /mnt/data/home/bambams/src/tetrist/game)

 496 (48 direct, 448 indirect) bytes in 2 blocks are definitely lost in loss record 1,499 of 1,522
    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0xA8BC2B9: ??? (in /usr/lib/x86_64-linux-gnu/dri/r600_dri.so)
    by 0x5110A32: _al_ogl_lock_region_new (ogl_lock.c:136)
    by 0x509144E: al_lock_bitmap_region (bitmap_lock.c:108)
    by 0x50915A7: al_lock_bitmap (bitmap_lock.c:129)
    by 0x5090288: transfer_bitmap_data (bitmap.c:579)
    by 0x5090288: al_clone_bitmap (bitmap.c:675)
    by 0x5093887: al_convert_bitmap (bitmap_type.c:177)
    by 0x5093DEA: _al_convert_to_memory_bitmap (bitmap_type.c:313)
    by 0x50EA9D7: convert_display_bitmaps_to_memory_bitmap (xdisplay.c:598)
    by 0x50EA9D7: xdpy_destroy_display (xdisplay.c:719)
    by 0x402681: deinitialize (in /mnt/data/home/bambams/src/tetrist/game)
    by 0x401A8A: main (in /mnt/data/home/bambams/src/tetrist/game)

 1,688 (136 direct, 1,552 indirect) bytes in 1 blocks are definitely lost in loss record 1,509 of 1,522
    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x5F041FC: ??? (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
    by 0x5F04770: ??? (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
    by 0x5F0604E: ??? (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
    by 0x5F0687B: _XlcCreateLC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
    by 0x5F2768F: _XlcUtf8Loader (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
    by 0x5F0DE4D: _XOpenLC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
    by 0x5F0DF87: _XlcCurrentLC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
    by 0x5F0DFBD: XSetLocaleModifiers (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
    by 0x50F0DCF: x_keyboard_init (xkeyboard.c:760)
    by 0x50F0DCF: xkeybd_init_keyboard (xkeyboard.c:929)
    by 0x50AD3E9: al_install_keyboard (keybdnu.c:129)
    by 0x402D10: initialize (in /mnt/data/home/bambams/src/tetrist/game)

 3,528 (400 direct, 3,128 indirect) bytes in 1 blocks are definitely lost in loss record 1,513 of 1,522
    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x5763A50: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
    by 0x573938C: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
    by 0x5739968: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
    by 0x50EFF09: _al_xglx_config_create_context (xglx_config.c:570)
    by 0x50EC41C: xdpy_create_display_locked (xdisplay.c:438)
    by 0x50ECBF2: xdpy_create_display (xdisplay.c:583)
    by 0x50A67D4: al_create_display (display.c:53)
    by 0x402D30: initialize (in /mnt/data/home/bambams/src/tetrist/game)
    by 0x401919: main (in /mnt/data/home/bambams/src/tetrist/game)

 LEAK SUMMARY:
    definitely lost: 625 bytes in 6 blocks
    indirectly lost: 5,128 bytes in 54 blocks
      possibly lost: 0 bytes in 0 blocks
    still reachable: 224,048 bytes in 1,898 blocks
         suppressed: 0 bytes in 0 blocks
 Reachable blocks (those to which a pointer was found) are not shown.
 To see them, rerun with: --leak-check=full --show-leak-kinds=all

 For counts of detected and suppressed errors, rerun with: -v
 ERROR SUMMARY: 359 errors from 8 contexts (suppressed: 0 from 0)

These all appear to be inside Allegro though which has me confused. I think I'm doing a decent job of cleaning up Allegro at the end of the program. I even tried adding al_uninstall_system() just to see if that would make a difference, but it didn't.. Is this a bug in Allegro or a bug in my program? :-/

Eric Johnson
Member #14,841
January 2013
avatar

Samsung is the "go to" but I basically just buy whatever is on sale and I've had great luck so far.

Did you put your entire OS on it, or just games and other software? If I got an SSD, I'd probably just use it for games and nothing more.

Chris Katko
Member #1,881
January 2002
avatar

OS. DEFINITELY.

Then put a couple games you want really fast at the time and swap them out as necessary.

Get a 256 GB or larger or you'll be sad. Because 128 GB gets eaten up almost IMMEDIATELY by the P.O.S. that is Windows 10. It keeps every VERSION of every driver it ever downloaded and if you delete them manually, it corrupts windows. (Don't forget >2GB for Candy Crush that you never asked for!)

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Eric Johnson
Member #14,841
January 2013
avatar

Why put the OS on there? Why not keep the OS on the HDD and put games on the SSD? Windows 10 is plenty fast on my HDD. Seems like a waste.

Neil Roy
Member #2,229
April 2002
avatar

SSD's may be faster, but one thing bothers me about them, and it is relatively minor, depending on how paranoid you are. And that is that you cannot run a program to erase old data from the drive, you know, to make certain it is really deleted like you can on standard HDDs.

If you're not worried about someone running software to recover your deleted files, than, no problem. I don't tend to worry about those sorts of things. Personally, I am happy with my standard HDD, it's cheaper and bigger.

---
“I love you too.” - last words of Wanda Roy

Eric Johnson
Member #14,841
January 2013
avatar

If you're paranoid, you shouldn't be content with data-deleting software on an HDD either. If there is anything that you must have deleted with absolute certainty, just destroy the hard drive. Do your zero-fill format, then bash it in with a hammer for added measure. I wouldn't trust a format on any storage medium if my life depended upon it.

Neil Roy
Member #2,229
April 2002
avatar

The data erasing software is pretty good. It just doesn't work on an SDD due to how they save files.

I had a friend give me two systems with two hard drives. I have software that can recover files from a formatted drive and I couldn't get ANYTHING off of his drives, he was pretty through. It actually made me laugh at the time as he knew what I was like and that i could recover it. ;) It showed me that the software for erasing was pretty good at what it does.

In another system I got, the drives were formatted and just a fresh OS was installed. I was able to recover most of their personal photos and what type of porn they liked to browse for. :) (I erased it all later, I just like to see what all I can recover, and this is OLD software that I use, like, 15 years old or more)

---
“I love you too.” - last words of Wanda Roy

Chris Katko
Member #1,881
January 2002
avatar

Why put the OS on there? Why not keep the OS on the HDD and put games on the SSD? Windows 10 is plenty fast on my HDD. Seems like a waste

Try it. :P ::)

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Eric Johnson
Member #14,841
January 2013
avatar

I don't think I'll put the OS on the SSD. That would be a waste. I don't use my computer for anything other than gaming, so I'd only be concerned with putting games on the SSD, nothing else.

Chris Katko
Member #1,881
January 2002
avatar

I don't think I'll put the OS on the SSD. That would be a waste. I don't use my computer for anything other than gaming, so I'd only be concerned with putting games on the SSD, nothing else.

Last thing you want is your OS responsive! ::)

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

bamccaig
Member #7,536
July 2006
avatar

I just tried to post this in the AllegroForthKit thread, but I guess by the time I had typed it and submitted it the thread locked... :-/

--

REPLs are great, but one of the things I really wish they had was the ability to automatically persist changes to code into a file. For example, if you redefine a function in the REPL, it would be nice if it figured out which file defined the function and replaced the function in the file. Obviously, you'd need source control to prevent loss from this, but you should be using that anyway. Even if you just needed to invoke a "commit" function with the REPL to write the changes to disk it would at least give you something. I hate having to copy/paste between windows. I.e., Either rewrite the function in the file and copy it to the REPL to test it, or test it in the REPL and then recall it to copy/paste back to the file. It's needless waste when a computer should be able to do that for us. Not sure if Forth's REPL is better than other ones I've used, but none of the ones I'm familiar with seem to support automatic persistence of code changes.

On a side note, the second time I saw the thread title (and forgot what the thread was) I immediately thought that there must be some kind of clever pun here having Allegro five bindings in Forth... Perhaps you could come up with one to help market the library. :)

Chris Katko
Member #1,881
January 2002
avatar

bamccaig said:

These all appear to be inside Allegro though which has me confused. I think I'm doing a decent job of cleaning up Allegro at the end of the program. I even tried adding al_uninstall_system() just to see if that would make a difference, but it didn't.. Is this a bug in Allegro or a bug in my program? :-/

When I ran Valgrind to try and find my Allegro + DAllegro, D program, it was firing off like over a million events and stopped after that. Before my app loaded. It was during the Allegro "start an initial window and then close it." part.

Don't know if it's only on Linux, in Allegro, DAllegro, or a driver problem as the call stack goes all the way into the graphics driver. No idea.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

bamccaig
Member #7,536
July 2006
avatar

Polybios
Member #12,293
October 2010

Don't know if it's only on Linux, in Allegro, DAllegro, or a driver problem as the call stack goes all the way into the graphics driver.

I've had these for years on Linux with C/C++. I've tracked them a bit and got the impression that it was neither my nor Allegro's fault.

Peter Hull
Member #1,136
March 2001

bamccaig said:

I just tried to post this in the AllegroForthKit thread, but I guess by the time I had typed it and submitted it the thread locked...

I also I think they are locked too quickly

Quote:

REPLs are great, but one of the things I really wish they had was the ability to automatically persist changes to code into a file.

On REPLs, I've used CIDER quite a bit. I use the actual REPL for evaluating but not defining things. I add/edit in the source files and use 'cider-eval-defun-at-point' This recompiles just the one function and so is instantaneous, which means I can use it very frequently to build up the function as I go. What you describe is more like how Smalltalk works, with a 'world' that you save to disk rather than having source files. I never got the hang of that.

bamccaig
Member #7,536
July 2006
avatar

More so I want for the VM to keep track of where a particular function definition came from. E.g., foo.lisp:3,4. And it should be smart enough to scan the file again to find it even if the file has changed, but the hint would be enough so it didn't have to scan the entire source tree again. Once it found the function it would overwrite it with the newly defined function from the REPL, and then finish off the file with the remaining contents (effectively editing the function in-place). If this worked automatically then you wouldn't even need to touch the source files during your hacking session. You could just redefine functions and have them automatically persist in your source code. The only time you'd have to touch the files is when you wanted to refactor them somehow. The REPL could even have a function for sending a function to a file, and if the function didn't exist in the file yet, it'll be appended and remembered from then on. Smells like productivity.

I just remembered that Emacs basically allows you evaluate Lisp expressions under the cursor using a command. So in Emacs you kind of sort of don't have this problem because you can just evaluate the code in the REPL directly from the file. However, I can't get by using Emacs for every long because I find it's too cluttered and my Vim-fingers inevitably do something not supported by Evil-mode (or else I learn of an Emacs command that no longer works because I've overridden it with Evil-mode). In any case, I think that having editor integration can be a solution to help with it. If your REPL can be integrated into your editor then it can be made more easy I think. Sort of like an IDE, except without a damn mouse. >:(

Neil Roy
Member #2,229
April 2002
avatar

Fascinating computer build, check it out, especially note the 2TB SSD! :o

video

---
“I love you too.” - last words of Wanda Roy

MiquelFire
Member #3,110
January 2003
avatar

I don't know what started me down that rabbit hole, I but saw that on my feed on Youtube a while back.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

Eric Johnson
Member #14,841
January 2013
avatar

I saw that a few days ago. It's a neat build; reminds me of a coffee machine.

bamccaig
Member #7,536
July 2006
avatar

One of the main things I've taken away from that (aside from the fact that I could never do it, but I think I understand it) is this:

2 TB SSD for $500 (USD probably). :o That is a bit expensive, but not as expensive as I might have imagined it.

MiquelFire
Member #3,110
January 2003
avatar

Last I seriously checked, the 1TB SSDs was around the 200-300 USD amount. And without doing any real work outside of cloning, that is the size I need to upgrade my current computer >.>

I feel jealous of whoever said they don't need SSD for their Windows OS.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

bamccaig
Member #7,536
July 2006
avatar

{"name":"1m20tf.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/6\/766c0551542ac1385ce85d3b8451fcdc.jpg","w":504,"h":500,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/6\/766c0551542ac1385ce85d3b8451fcdc"}1m20tf.jpg

Chris Katko
Member #1,881
January 2002
avatar

That's !@#!@#$ing hilarious.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

DanielH
Member #934
January 2001
avatar

[bamccaig]

For those that know how to pick a lock, it doesn't quite work that way. Funny nevertheless.



Go to: