Wikipedia:Reference desk/Archives/Computing/2014 September 21

= September 21 =

Purchasing New Hard Drives
Hello all, I have never purchased a new hard drive for my Windows 7 machine. I'm planning on buying these hard drives from Amazon. My question, does anything special need to be done to hard drives like this before using them? I know that when I set up some virtual hard drives in virtual machines of old OSes (such as 95/98/etc), I had to FDISK and FORMAT them. Is there the requirement to do that, or any other special step that needs to be done? In addition, do you think my choice of hard drive/company is a good one? Do you have any suggestions on better hard drives? Thanks! -- Tohler (talk) 14:23, 21 September 2014 (UTC)


 * You will probably have to format the disk (which you do in the Disk Management screen, which is part of Control Panel). As to which manufacturer: the only large-scale study of consumer disks that I'm aware of which calls out brands is this one one from online storage company Backblaze: that doesn't make Seagate look good, but note that at the end they say they're still mostly buying Seagates (but their storage infrastructure is probably more used to the bother of swapping out a failing drive is an individual user like you or I). -- Finlay McWalterᚠTalk 16:09, 21 September 2014 (UTC)


 * Before making your purchase, check to see if you have the necessary cables, since bare drives usually come without cabling. A typical system power supply will have several extra SATA power cables. The motherboard will typically have extra SATA data ports, but you will need a data cable. Your original system purchase may have included one, but if not, now is the time to add one to your order. --  Tom N  talk/contrib 18:13, 21 September 2014 (UTC)


 * There are a few problems specific to large disks: the normal partitioning scheme, MBR, can only address 2TB (or 2.2TB depending on the definition of TB), so you would not be able to use the full capacity of your 3 TB disk. To fix that you'll have to choose GPT; if you are adding a disk for extra storage, you won't have any problems. . If however the disk has to be bootable (if you are replacing your old disk and want to install windows on the new one) then your system has to be UEFI-capable; older systems only have BIOS, and BIOS can only boot from an MBR partition, not from GPT. One other requirement in that case: your Windows 7 must be a 64-bit version. (see http://support.microsoft.com/kb/2581408 for more details) If your system only supports BIOS, you can still boot from the disk and use the full capacity by installing Seagate's DiscWizard device driver: it will create a second MBR for the part above 2.2 TB, basically pretending to be two physical disks instead of one. (http://www.seagate.com/support/downloads/discwizard/). Ssscienccce  (talk) 19:21, 21 September 2014 (UTC)

Calling DLLs From Ruby
I've been looking at how to use win32api objects to call functions from DLLs inside of Ruby. The basic idea makes sense, as does most of what I've seen. However, my stumbling point is on how exactly they pass data back and forth, none of the tutorials or examples I've found seem to go into this enough for me to do it on my own. Do I need to write my functions, in the DLL, in a specific way to interface with Ruby (I'm guessing not since it can call to libraries I know were not made with Ruby in mind)? For something concrete, supposing I had a function, in the DLL, that took two longs and returned their sum, if I wanted to call it from Ruby with args 3 and 4, what I would pass to the dll, what would be returned, and what would I do with it? Finally, from what I've read, it looks like you can return pointers to data back to Ruby, but what would you do with them once received? Or have I got this wrong? --related, but not essential, if my functions in the dll need to use data from a file, can it load the data into memory and have it stay there, or does it disappear after the function call? Essentially, is it like a second program running side by side and communicating, or is it more like something that starts fresh every time I ask it to do something? --I know I am asking a lot here, any help would be welcome; even some links to a few obvious examples. Thank you all:-)Phoenixia1177 (talk) 18:10, 21 September 2014 (UTC)


 * Your options include Ruby FFI (which I think uses its own scheme for describing the Ruby<->native interface) and Fiddle, which is a Ruby wrapper over libffi. -- Finlay McWalterᚠTalk 19:34, 21 September 2014 (UTC)


 * I don't know much of anything about Ruby but I can answer your question in a broader context. I'll use "Ruby" and "C" as the language names, but this applies to most interfaces between garbage-collected and non-garbage-collected languages.
 * Normally the DLL will be loaded once and will stick around after that. Any heap objects you allocate on the C side will stick around between calls. They will remain even if there are no more references to them, because Ruby's garbage collector doesn't understand the C heap, so you need to explicitly free them somehow to avoid memory leaks. You can think of the Ruby and C code as parts of the same program. They don't run in parallel; the C code only runs if you call it from Ruby, and it uses the same call stack as Ruby.
 * A foreign function interface will typically provide a way to wrap a C function in a Ruby function. You give it a C function pointer (or the name of a DLL and an export in it) and the parameter and return types, and it will return a Ruby function that, when called, will coerce its arguments into the appropriate C types and call the C function, then coerce the return type back to a Ruby object. It looks like Win32API will do this. The documentation is pretty anemic, but you might write something like Win32API.new("mydll", "myexport", ['L'] * 2, 'L') to wrap your function that adds two longs. Per this page, there's also an optional argument to specify the calling convention. C compilers normally use cdecl, but the default for this argument (and for Windows DLLs) is stdcall. You need to either make sure your C functions use stdcall or else pass :cdecl for this argument (I'm assuming that's the spelling; the documentation doesn't say.)
 * Pointers (type 'P') can be passed and returned but are just magic cookies on the Ruby side; the only thing you should do with them is pass them back to C code. (Actually, an FFI might provide functions to directly read and write through pointers, but without loss of generality you can pretend that those are wrapped C functions.)
 * A good FFI may provide a way to wrap pointers in Ruby objects that automatically call an appropriate C function to free the pointer when the Ruby object is garbage collected, to make C heap objects easier to manage. And it will provide a way to make C wrappers for Ruby functions, so that you can write C callbacks in Ruby. -- BenRG (talk) 20:17, 21 September 2014 (UTC)


 * Thank you for the suggestion Finlay, unfortunately, I must use Ruby's basic win32api object for this. I worked out a very speedy pathfinding algorithm that operates off of using a small collection of previously calculated data points from the map geometry - whatever she is using this in requires using an old basic version of Ruby (I think it's something like rpg maker, maybe it is, she didn't say for some reason, oddly). BenRG: thank you for the perspective, it is very helpful and has clarified a few points I was finding a bit murky.Phoenixia1177 (talk) 21:40, 21 September 2014 (UTC)