Jump to content

Wikipedia:Reference desk/Archives/Computing/2013 December 11

From Wikipedia, the free encyclopedia
Computing desk
< December 10 << Nov | December | Jan >> December 12 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


December 11

[edit]

stack/heap in Java

[edit]

hello can someone look over my assignment and see if I understand whats on the stack/heap in Java? Its these two documents [1] [2]

The only one I am uncertain of, is strings. when a string is in a method, its in the stack, right? but if its declared as a global variable, its on the heap? or is a string always in the heap?Sdjkgkdjfag999 (talk) 00:56, 11 December 2013 (UTC)[reply]

In Java, Strings are objects; literal strings represent references to objects (and the compiler may choose to coalesce these into a single object). The basic rule is, "all objects get allocated on the heap." Strictly speaking, the language specification does not say where objects will be allocated (on the stack or the heap): except that heap data is accessible across all threads. In practice - every Java VM you will probably ever use, like HotSpot and OpenJDK and so forth - will allocate strings on the heap. You can read more about HotSpot at the Runtime Overview from OpenJDK. Nimur (talk) 01:23, 11 December 2013 (UTC)[reply]
As a stunning counter-example, JRockit may choose to allocate a short string in a Thread Local Area. But don't put this down as the answer to your homework problems unless you want to spend some time arguing about memory-management strategies with your teacher/TA/professor. The canonical answer is, "Strings go on the heap." Nimur (talk) 01:29, 11 December 2013 (UTC)[reply]
OK thanks guys.Sdjkgkdjfag999 (talk) 01:37, 11 December 2013 (UTC)[reply]

building binary search tree from a bunch of numbers

[edit]

another question... i was given the numbers 38 14 12 6 28 18 4 19 13 16 30 and had to create a binary search tree. How do you create the tree based on that? what number is the root? i dont know where to startSdjkgkdjfag999 (talk) 01:51, 11 December 2013 (UTC)[reply]

this is what i get

                       38
                     /    \
                  14         28
              /      \     /    \
             6      12    18    19
             \          /   \     \
              4        13    16     30

but it looks seriously screwed up, and there's really no method to my madness.Sdjkgkdjfag999 (talk) 02:05, 11 December 2013 (UTC)[reply]

The first item is the root. The result is going to be seriously unbalanced, with the entire tree sprouting from the left branch. That's still a tree: it's a tree in need of rebalancing. (If you're supposed to be acting as a Self-balancing binary search tree, you'll do the rebalancing yourself as you go along.)  Card Zero  (talk) 02:27, 11 December 2013 (UTC)[reply]
See Binary search tree. You started correctly by making the first number (38) the root. But 12 < 14, so 12 should move left from 14:
                       38
                     /
                   14
                 / 
               12
You also made other errors but maybe you now know how to fix them. PrimeHunter (talk) 02:35, 11 December 2013 (UTC)[reply]

alright... i think i understand it now. is this correct:

                38
              /    
            14
         /       \
        12        28
      /   \      /   \
    6     13    18    30
   /           /  \
  4           16   19

also, what about theese numbers: 23 18 38 14 12 6 28 16 7 15 13 32 30

             23
           /    \
          18      38
        /         /
        14        28
      /   \        \
     12    16       32
   /  \   /         / 
  6   13  15       30
   \
    7

is that correct?Sdjkgkdjfag999 (talk) 19:30, 11 December 2013 (UTC)[reply]

Yes. These trees can also be rearranged to be flatter, which would make them better balanced trees, but doesn't seem to be what you're being asked to do. You've got the hang of the rule now, anyway: for each node, higher numbers go into the right child node and lower numbers go on the left.  Card Zero  (talk) 00:32, 12 December 2013 (UTC)[reply]

Writing out contents of ADF files

[edit]

My KryoFlux controller has arrived now, and it seems to be working OK. I'm currently in the process of transferring my several hundred Amiga disks to ADF files. E-UAE can emulate an Amiga floppy drive from an ADF file, so I can already get at the disks' contents through E-UAE, but I'd like to write the contents to real Linux files. Is there a way in Linux to write out the contents of an ADF file as normal files? JIP | Talk 18:40, 11 December 2013 (UTC)[reply]

There's an open source ADF library, adflib which includes unadf, an "un-tar" equivalent for ADF. pyADF, a Python wrapper over adflib, has a rudimentary command-line shell allowing you to dir, get, put, and print files inside the ADF. -- Finlay McWalterTalk 21:43, 11 December 2013 (UTC)[reply]
I downloaded the ADFlid package, but my attempt to build it resulted in numerous errors. I have contacted the author about it. This ADFlib package seems to be the only tool in existence capable of writing out the contents of ADF disk image files. If everything else fails, I still have the option of going through every single ADF disk image file in the E-UAE emulator, as it is perfectly capable of writing files directly to the host Linux file system. It will, of course, be much slower, so I'd rather avoid it. JIP | Talk 18:35, 12 December 2013 (UTC)[reply]
A binary unadf package is in the standard Ubuntu repositories. -- Finlay McWalterTalk 22:08, 12 December 2013 (UTC)[reply]
I had to install the libtool package, but after that it all built fine (the .so and the unadf executable) without issue. -- Finlay McWalterTalk 22:13, 12 December 2013 (UTC)[reply]
I still got the same errors even after installing libtool. I contacted the author of adflib, and he pointed me to this site: https://github.com/tonigi/ADFlib. After I downloaded the repository as a ZIP file, the adflib package built all OK. JIP | Talk 07:35, 14 December 2013 (UTC)[reply]

Floppy disk deterioration

[edit]

Keeping within my software preservation theme, now that I am transferring my old Amiga disks to a modern PC using KryoFlux, I have noticed that very few of the disks have read errors. Two years ago, when I was doing the same for my old Commodore 64 disks, a great deal of them had read errors, rendering those disks unusable. Now my old Commodore 64 disks were 5.25" disks, while my old Amiga disks are 3.5" disks. The Amiga disks are also about half a decade younger than the Commodore 64 disks. Do 5.25" disks deteriorate faster than 3.5" disks, or is this result simply because the disks are younger? JIP | Talk 21:30, 11 December 2013 (UTC)[reply]

Just a guess, but the hard case around the smaller disks may offer some protection, say from UV light and moisture. StuRat (talk) 03:24, 12 December 2013 (UTC)[reply]
Yes, I've noticed the same effect. In theory, the larger discs should deteriorate less because the recording tracks are much wider, but Stu's guess sounds good to me. I've seen mould growths on the recording surfaces of both types of disc when they have been kept in less than perfect conditions. Dbfirs 09:03, 12 December 2013 (UTC)[reply]
I recently converted 30 year old 5.25" disks for apple. Most were completely OK. They were stored in dark dry conditions. Graeme Bartlett (talk) 10:50, 12 December 2013 (UTC)[reply]