Wikipedia:Reference desk/Archives/Computing/2009 May 23
Computing desk | ||
---|---|---|
< May 22 | << Apr | May | Jun >> | May 24 > |
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. |
May 23
[edit]C++ question
[edit]I have some objects of a particular class. I want some way to call a specific function of all those objects without making a loop. By using base class,virtual class,etc. Please suggest a way to do that! 218.248.80.114 (talk) 01:47, 23 May 2009 (UTC)
- Well, the easiest way to achieve what you describe is to make a loop, or use for_each, but the latter is hardly an improvement. Consider:
#include <algorithm> // for_each
#include <functional> // mem_fun_ref
struct C { void f() const {} };
int main()
{
using namespace std;
C c[10] = {}; // array of 10 C objects.
for_each( c, c + 10, mem_fun_ref(&C::f) ); // call f() for all C objects.
}
- If you could describe your problem in more detail or show some code it will be easier to give more detailed advice. decltype (talk) 03:11, 23 May 2009 (UTC)
class C {
virtual void exec();
};
class A : public C {
void exec();
};
int main() {
A a1,a2;
a1.exec();
a2.exec();
}
Instead of calling exec() for both a1 & a2 or by using a loop, I want to use the property that exec() is derived from the same base class and execute all the derived exec()'s by a single function call. Thanks for the response. —Preceding unsigned comment added by 218.248.80.114 (talk) 03:31, 23 May 2009 (UTC)
- I see. Unfortunately, there isn't a way to do that that doesn't involve a loop or recursive function call somewhere. decltype (talk) 03:45, 23 May 2009 (UTC)
- Why do you want to avoid loops? — Matt Eason (Talk • Contribs) 12:18, 23 May 2009 (UTC)
- You could make the objects connect themselves up into a linked list (have a 'next' pointer in every object and a static 'first' variable - then hook up the linked list in the constructor function and unhook it in the destructor). Now have the specific function do whatever it does - then at the end, have it call that same function on the 'next' object in the list. This is a recursive solution - no loops involved. However, recursion eats up stack space and the list processing adds lots of overhead - so is wasteful in this situation - you're better off using a loop.
class Thing
{
Thing *next ;
public:
static Thing *first ;
Thing () { next = first ; first = this ; }
void execAll () { exec () ; if ( next ) next -> execAll () ; }
virtual void exec () { whatever ; }
}
Thing *Thing::first = 0 ;
int main()
{
Thing a1, a2;
Thing::first->execAll(); // calls 'exec' on every Thing in existence!
}
Derived classes of 'Thing' will work just fine. SteveBaker (talk) 02:39, 24 May 2009 (UTC)
- Given
class Thing
above, and ignoring copying and assignment, how would you implement the destructor? considerThing * p; {Thing a1; p = new Thing(); Thing a2; } Thing::first->execAll();
decltype (talk) 07:52, 24 May 2009 (UTC)- I was hoping you wouldn't ask that! I didn't want to complicate a simple answer. But what I'd do would depend on how time-sensitive the creation and deletion 'Thing' objects is - and how sensitive the memory they consume is. If time is critical but space isn't - then I'd build a doubly-linked list with both 'prev' and 'next' pointers. If space is critical but time isn't then I'd have the destructor walk down the linked list from 'first' until it finds a node whose 'next' equals the 'this' pointer of the node I'm trying to delete. From then on, it's easy.
- Time-critical version with doubly-linked list:
class Thing
{
public:
Thing *next ;
Thing *prev ;
static Thing *first ;
Thing () { if ( first ) first->prev = this ; next = first ; prev = 0 ; first = this ; }
virtual ~Thing () { if ( prev ) prev->next = next ; else first = next ; }
...etc...
} ;
- Space-critical version that searches the single linked list in order to remove a node:
class Thing
{
public:
Thing *next ;
static Thing *first ;
void unlink ( Thing *thing )
{
if ( next == thing )
next = thing -> next ;
else
if ( next )
next -> unlink ( thing ) ;
}
Thing () { next = first ; first = this ; }
virtual ~Thing ()
{
if ( first ) first -> unlink ( this ) ;
}
...etc...
} ;
- (The above code is untested - I may have made a boo-boo - so beware!)
- Of course, in reality - I'd be unlikely to deny myself the use of loops in the first place! Also, I don't like public member variables - so I'd probably hide more stuff in the 'private' section. Some of the cases that the code catches (like when 'unlink' tests that 'next' is null) can "never happen" so I could save time by converting the checks into asserts so they'd be compiled out in a shipping build...and of course this is not thread-safe. There is a vast, yawning chasm between what one writes as an example for Wikipedia and finely crafted working code!
- SteveBaker (talk) 15:21, 24 May 2009 (UTC)
I used \renewcommand to make the "enumerate" environment label each item with a capital letter followed by a period, thus:
\renewcommand{\labelenumi}{\Alph{enumi}{.}}
renewcommand{\theenumi}{\Alph{enumi}}
\begin{enumerate}
\item so there
\item and so on
\item blah blah
\item \label{thisgap}
\end{enumerate}
We will see that any gap of the kind described in (\ref{thisgap}) corresponds to a
I expected a sentence that says
- We will see that any gap of the kind described in (D) corresponds to a
but instead I got this:
- We will see that any gap of the kind described in (4) corresponds to a
How can I get it to show a (D) rather than a (4)? Michael Hardy (talk) 02:19, 23 May 2009 (UTC)
- I would use
\renewcommand{\theenumi}{\Alph{enumi}}
. MTM (talk) 18:09, 23 May 2009 (UTC)
Thank you, MTM. It worked. Michael Hardy (talk) 21:03, 25 May 2009 (UTC)
Recovery of SATA drive on PATA computer
[edit]I have a SATA HDD of my friend's computer in which the power supply failed. They bought a new desktop, but I don't have access to it. All I have here at my house are PATA computers. So, is there anyway I can go PATA to SATA for data recovery without any extra equipment (I have permission to take the computer with the messed up powersupply so I could sacrifice some parts of it.)? TIA, Ζρς ιβ' ¡hábleme! 03:27, 23 May 2009 (UTC)
- Nope. You couldn't even hook up the SATA drive to any connector that your computer has, if it lacks SATA support (which you can add to a PATA computer by purchasing a SATA PCI card). Tempshill (talk) 03:31, 23 May 2009 (UTC)
- Tempshill is right, There is no way that you can connect a sata HHD to a computer that lacks sata ports without getting new equipment. But, the equipment to do so is reletivly cheap. This, this, this and this are all about the same price depending on where you go. Personely i have one of these and i have to say it is very usfull. I got mine at Frys for about $14. Hope this helps. – Elliott(Talk|Cont) 05:08, 23 May 2009 (UTC)
- Thought. Have a thumbdrive? (aka flashdrive). Take your (good) power supply out, install to friends (dead) PC, dump data to usb, revert P/S - copy said data to desirable location. Any value to that thought? — Ched : ? 05:28, 23 May 2009 (UTC)
Telnet/SSH2
[edit]Following on from my question about port forwarding, I have succesfully set up the forwarding of port 22 (and port 80) and tested that my webserver serves up the pages of my test site and I can use SSH2 to connect a telnet window to my webserver for remote admin. It all works well - at home. So now I've left the webserver running and gone to my sister's for the weekend. The webserver is still serving up the pages, but I cannot get the SSH2 window to connect before it times out. So is there anything obvious I have failed to consider? Astronaut (talk) 09:17, 23 May 2009 (UTC)
- Your client side (e.g. your sister's home network or internet provider) might be blocking certain ports. Have you tried accessing from other locations? Nimur (talk) 12:01, 23 May 2009 (UTC)
- I tried a neighbour's unsecured wireless connection and had the same problem, but it is quite possible that they are with the same ISP as my sister. Then again, perhaps the port blocking is a feature of all ISPs here in the UK. It did get me thinking that perhaps it might have something to do with the multiple firewalls somewhere in the route between my sister's network and my own (my ISP, my sister's ISP, and perhaps some more). One other thing also occured to me, would I need to set up some kind of VPN to make this work properly? (if so, why?). Anyway, I'll call my ISP next week and see if they can help. Thanks. Astronaut (talk) 16:34, 23 May 2009 (UTC)
- Your server side ISP could also be blocking the inbound connection. Or your firewall is blocking it. Or your router might be blocking it because it's set up to be configured through ssh. – Elliott(Talk|Cont) 16:33, 23 May 2009 (UTC)
- My modem/router is definitely configured to forward ports 22, & 23 (SSH and Telnet, respectively) to the server. My tests at home consisted of accessing my server using SSH2 via both the internal IP address of my server (to check the SSH2 was working) and the external IP address of my router (to check the port forwarding was working). Both tests were successful. I'm definitely getting the feeling the problem is firewall related (perhaps the external IP test manages to avoid my ISP's firewall?), but I just wanted to check that I hadn't missed out something really obvious to a networking expert but not at all obvious to me. Astronaut (talk) 16:52, 23 May 2009 (UTC)
FSB vs. memory speed
[edit]I am comparing two laptops: [A] has 667 Mhz FSB and 800 Mhz dual-channel memory, whereas the [B] has 800 Mhz FSB and 667 Mhz dual-channel memory. Which would be faster? And why? Thanks! --Masatran (talk) 09:46, 23 May 2009 (UTC)
- Some more details: [A] is Pentium Dual-Core, while [B] is Core 2 Duo. Intel Core 2#Synchronous memory modules recommends synchronizing FSB and memory speeds, but does does not say what happens when they are not in sync. --Masatran (talk) 10:11, 23 May 2009 (UTC)
- Core 2 > Pentium Dual-Core. In general memory clock isn't much of a factor in determining the performance compared to other things (CPU speed, GPU, amount of ram, etc.). --antilivedT | C | G 11:16, 23 May 2009 (UTC)
- Antilived is correct that your CPU choice here will have a much greater impact than your memory timing choices. This chart from Tomshardware from January 2008 compares FSB and memory speeds from 1066 to 1600, and shows that the differences using different FSB and memory timings when playing Quake 4 and F.E.A.R. are tiny, and are probably exceeded by measurement error. Other benchmarks in the same article, other than raw, synthetic memory bandwidth measurements, show even smaller differences, or no differences; from a practical point of view you will most likely not notice a difference, unless, possibly, your laptop tasks involve all memory access and little calculation, as though you were just sorting gigabytes of data all day. To answer the question about memory timing, I believe system (A) will actually clock the memory at 667MHz, so you will simply have memory that's rated for a higher speed than your laptop will drive the memory at; and system (B) will detect upon bootup that the memory is 667MHz, and underclock the FSB accordingly. In both situations you'll be running your memory at 667MHz. Tempshill (talk) 14:48, 23 May 2009 (UTC)
- It probably won't run the FSB to 667Mhz but rather lower the memory multiplier so that FSB runs at 800 while memory runs at 667Mhz. Sure there's a performance hit from doing this, but it is a lot smaller than the difference the CPU speed makes. --antilivedT | C | G 08:16, 24 May 2009 (UTC)
external hard drive problems
[edit]Got a bit of a problem with one of my external usb hard drives. The problem only began about an hour ago. The drive has two partitions, a 198GB fat32 one and a 40GB NTFS one. When I plug the drive into the usb port, only the 198GB fat32 drive shows up, but after a few seconds the entire computer freezes and becomes unresponsive. However, as soon as I unplug the drive the computer resumes working like nothing is wrong. The system is Windows XP. I've tried on another WinXp computer and exactly the same thing happens. The drive is not making any clicking sounds, I've not installed any new software and my other usb drives are working fine, so it's not a problem with the usb port or the usb cable either. Any ideas? —Preceding unsigned comment added by 82.44.54.169 (talk) 10:43, 23 May 2009 (UTC)
- This is a hard one. There could be any number of things wrong (failing sectors, wire in side the case could be lose, control board could be fried. ect...). But from the details you have given i'd have to say that the drive might be bad. The only way to really see if that is the case would be to restart your computer using a Ubuntu live cd. See if you can access the drive from that live CD. IF you can try to get rid of the partitions, formatting the hard drive and reforming the partitions. If after doing that you still cant access it from windows then consider that drive bad. Let us know how it turns out. I hope this helped – Elliott(Talk|Cont) 16:29, 23 May 2009 (UTC)
- Thanks for the suggestion. It's working perfectly under slax, so I'm at a complete loss for why it's not working on windows :/ —Preceding unsigned comment added by 82.44.54.169 (talk) 19:15, 23 May 2009 (UTC)
- Well at least I managed to save most of my stuff from the drive. But unless I can get it working again with windows it's pretty useless to me. Has this sort of thing happened before? —Preceding unsigned comment added by 82.44.54.169 (talk) 19:22, 24 May 2009 (UTC)
Try using a USB cable with the splitter on the end for extra power (it splits into 2 USB plugs to plug into the PC, one is the normal connection (data + power) and the other is simply for extra power from a 2nd USB port). Perhaps that will work? I've found that some USB hard-drives fail to work on my laptop (compared to my friend's PC), or sometimes fail to work on particular USB ports, if I don't provide the extra power in this way. Zunaid 07:50, 25 May 2009 (UTC)
what is the algorithm behind online maps?
[edit]For example, a map of a city is viewed online and I move across the road using the mouse. If it is magnified, one can see that parts of the maps are only loaded as required. Can you please say how it is done? —Preceding unsigned comment added by 131.220.46.25 (talk) 12:04, 23 May 2009 (UTC)
- The algorithm is actually very simple. You have a current (x,y) location, and a current zoom level. The algorithm simply retrieves the images which represent areas near that (x,y) location (i.e. load everything in the range x-3 to x+3 miles). The efficiency comes from an effective data structure, storing the map image files for quick access. A more interesting algorithm is a query for driving directions - a complex web of interconnected streets must be searched to find a minimum-cost path (by distance, travel-time, etc). Nimur (talk) 12:20, 23 May 2009 (UTC)
- The general technique that is behind these maps is Ajax. Traditionally, when you interacted with a web page, your actions, such as filling out a form or clicking on a link or some other hot spot, caused the browser to send a request back to the server for new page content. That new content would replace part of all of the current page and the process would repeat. Generally you had to wait for each update. With Ajax, updating of the page is more finely controlled using JavaScript , which responds to your actions and, when needed, requests additional page content using a function called XMLHttpRequest. The difference is that the browser does not wait for the response and you can continue to interact with the current page. When the response does come back, another piece of JavaScript code is executed that takes the data and updates the appropriate portion of the display.
- In the case of Ajax driven maps, popularized by Google Maps, the map starts out at some initial position and zoom level. The initial map is likely downloaded with the initial page. As you roll your mouse wheel, the JavaScript code performs several actions: First, it re-sizes the existing displayed image, which may initially have a low resolution appearance. Next, it determines what new images are needed to provide the higher resolution presentation for the new zoom level. If it already has some or all of those images (from earlier activity), they are immediately displayed. For those images that are not available, one or more calls are made to XMLHttpRequest to request those images. A short time later, when the requested images are received back from the map server, the JavaScript will replace portions of the current map display with the higher resolution images, eventually updating the entire map.
- For efficiency reasons, those image requests are typically broken down into multiple sections or tiles. It is likely that the map server stores each tile as a separate image in its database. The images themselves come from several sources. Lower resolution images are based on satellite photos, while the higher resolution images are based on a aerial photography. Adjacent photographs are blended together to give the appearance of a continuous image, but you can often see discontinuities in color, lighting, and perspective where this has been done.
- Panning works similarly. Typically, the web page already contains image data for areas of the map lightly beyond the displayed area, so slow panning is often seamless. As you pan, the JavaScript will use XMLHttpRequest to request new images to fill in missing parts of the map and to maintain a small buffer of surrounding the displayed map. Overlays such as streets, borders, labels, and other information is retrieved and processed similarly. -- Tcncv (talk) 15:37, 23 May 2009 (UTC)
C# and Bluetooth
[edit]Hi. I am trying to write a C# program that can receive files over Bluetooth (OBEX PUSH), and display transfer progress. Currently I'm using the InTheHand.Net.Bluetooth library from 32feet.NET
ObexListener listener = new InTheHand.Net.ObexListener();
listener.Start();
while (listener.IsListening)
{
ObexListenerContext context = listener.GetContext();
Application.Run(new RecvProgress(context));
}
but GetContext() only returns after all data has been transferred.
Is there any other way to receive files over Bluetooth? (Windows XP Pro, Microsoft's Bluetooth stack)
--grawity 12:57, 23 May 2009 (UTC)
Mount folder on Ubuntu (Linux/GNOME)
[edit]Anyone knows how I can "mount" a folder on Ubuntu, so that it appears like this? I tried "mount --bind" on /media/myfolder_name, tried creating symlics, etc... nothing seems to work... is this even possible? I think some apps do it with FUSE, but I just can't figure out how... __ Hacktolive (talk) 18:02, 23 May 2009 (UTC)
- Nevermind, I solved it with some FUSE utilities (bindfs in particular)_ Hacktolive (talk) 18:20, 23 May 2009 (UTC)
I want XeTeX and I want it now...
[edit]I need to install XeTeX (and probably LaTeX as well) on my Windows Vista PC. But I'm not really comfortable with command-line based stuff with .tars and .bz2s and such, which is what all the distributions I've found offer. Is there somewhere on the Internet where I can get a nice big .zip containing all the necessary files and an installer that will do it for me? 137.205.74.169 (talk) 18:05, 23 May 2009 (UTC)
- Try MikTeX. MTM (talk) 18:12, 23 May 2009 (UTC)
- +1. And LyX as well. --wj32 t/c 23:45, 23 May 2009 (UTC)
Ipod
[edit]So, my Ipod is broken.
Neither my computer or laptop notice it when I plug it in, it doesn't recharge, plugging it in to one of the usb ports in my computer managed to set fire to part of it, and it now just shows the recharging message and does nothing else.
It stopped working the same a few weeks ago, and I sent it to be fixed, and it came back recharged, but now the battery has run out again, it's back to how it was, and it seems the free repair thing is about to run out. And when I got it back, all the music had been wiped off and without being able to connect it to my computer, I can't put anything back on, even if it did work.
Oh, and the wire to plug it in has gotten itself a bit broken too now, so I can't use that any more.
What do I do?
148.197.114.207 (talk) 18:50, 23 May 2009 (UTC)
- You say the warranty is "about to run out", so presumably it hasn't run out yet. That makes it simple - you just send it back in. --Tango (talk) 18:58, 23 May 2009 (UTC)
But they didn't actually fix it last time. What happens if it comes back just the same as it did before, just with the battery recharged again? 148.197.114.207 (talk) 19:09, 23 May 2009 (UTC)
- You mention that the wire is broken, could a short circuit be the cause of the failure of this ipod? Just send it in again and tell them that they didnt fix it last time, also mention the fire thingy. – Elliott(Talk|Cont) 20:05, 23 May 2009 (UTC)
The wire sort of got broke after the rest didn't work. But I will try letting them know the previous problems still haven't been fixed, they might do something. Or exchange it for a new one. 148.197.114.207 (talk) 21:00, 23 May 2009 (UTC)
- If you return something under warranty - but they fail to fix it - then you can send it back for them to fix even if the warranty has just expired. Just make sure that you make it clear to them that they failed to fix it last time. If they screw up AGAIN - you just keep sending it back with ever more exasperated explanations. If you call customer service and they can't understand this - employ the magic phrase "In that case, I need to speak to your supervisor." SteveBaker (talk) 02:30, 24 May 2009 (UTC)
Screen going blank during Windows XP installation
[edit]I am installing Windows XP from a CD (onto which I bundled service packs according to this guide) and it starts out just fine (much better than without the service packs, because without them, Windows can't handle the large hard drive (300 GB)).
It formats the hard drive and copies files over to it and then it wants to reboot, but when the CD boots again, the screen turns black and all CD and hard drive activity stops. It just sits there. If I disconnect the hard drive and boot with the CD, the installation program starts as normal, but not when the hard drive is connected. Since the installation isn't finished, the hard drive itself isn't bootable.
I would appreciate suggestions on what to do. —Bromskloss (talk) 19:34, 23 May 2009 (UTC)
- I think that windows xp (no SP) will support any one HD up to 4TB. Try installing windows without slipstreaming any service packs in to it. And make sure your CD is clean. :)– Elliott(Talk|Cont) 20:20, 23 May 2009 (UTC)