Wikipedia:Reference desk/Archives/Computing/2006 November 17

From Wikipedia, the free encyclopedia

Computing desk
< November 16 << Oct | November | Dec >> November 18 >
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.


Contents


[edit] November 17

[edit] Objective-C / Cocoa problem: object always nil

I am trying to program an app for Mac OS X, in Objective-C using Cocoa (API). A problem that I keep running into is that a NSNumber object keeps having a nil value. Below is a sample of my code, most of the program has been omitted, leaving the "troublesome code."

/* myClass.h */

#import <Cocoa/Cocoa.h>

#import <time.h>
@interface myClass : NSObject
{

        IBOutlet NSTextField    *timeText;
        IBOutlet NSDatePicker   *clock;
        
        
        NSNumber        *nextT; // problem object
        NSTimer         *drawTimer;
}
- (IBAction)go:(id)sender;

@end
/* myClass.m */

#import "myClass.h"

@implementation myClass
- (IBAction)go:(id)sender
{
    
        [nextT initWithLong:(time(0) + 1)]; // Why does this always come out as nil?
        
        drawTimer = [[NSTimer scheduledTimerWithTimeInterval:0.001
                target:self 
                selector:@selector(looping) 
                userInfo:nil repeats:YES] 
                retain]; 
}

- (void)looping // loops indefinitely 
{
        // textField that prints the system time (works correctly)
        [timeText setStringValue:[[NSDate date]descriptionWithCalendarFormat:@"%m/%d/%Y  %I:%M:%S %p" timeZone:nil locale:nil]];
        
        // inc datePicker by 1 second (does not execute because nextT = nil) 
        if ([nextT isEqualToNumber:[NSNumber numberWithLong:time(0)]])
        {
                [clock setDateValue:[[clock dateValue] addTimeInterval:1]];
                [nextT initWithLong:(time(0) + 1)];
        }
}
@end

When go is triggered, the date and time (according to the computer's clock) is printed in a textField (timeText), and a DatePicker (clock) (introduced in Mac OS X 10.4) advances by 1 second every time the system clock ticks 1 second (both should be in sync). However the "clock" fails to move because an if statement doesn't run.

according to the debugger, the NSNumber nextT has is nil value at all times during runtime, despite its initializations. I've tried it with constants, and variables alike. And have interchanged Int, UnsignedInt, Long, and every combonation of Int, Unsigned and Long.

Why is nextT always nil?

Kjammer 01:36, 17 November 2006 (UTC)

I'm taking a look at your code. I'll let you know in a jiffy. --Brad Beattie (talk) 10:50, 17 November 2006 (UTC)
So what you're looking to do here is have text field that updates every millisecond but only displays down to the second? --Brad Beattie (talk) 12:07, 17 November 2006 (UTC)

I know there are several more practical ways to do this. But the The thing I am concerned about is that something in this case is occuring where logicly it shouldn't be (intialized globals having nil values). Unfortuantly this is the only example I can think of to illistrate this.

nextT is always nil, even when setting it to any variant of int that's constant, variable or return value (time(0)). And yes time(0) form the time.h library works the way its meant to.

Documentation of NSNumber can be found here.

Kjammer 23:29, 17 November 2006 (UTC)

Uh, have you actually allocated any memory for the object?!

[edit] Wikipedia demographics

Are there any official demographics on who uses Wikipedia, besides just listing the obvious? -- Zanimum 02:00, 17 November 2006 (UTC)

Does Wikipedia even collect demographical information? Cbrown1023 03:36, 17 November 2006 (UTC)
Were you asked any when you created your account? Well, there is some: Wikipedia users in general:
  • Have access to a computer
  • Have the ability to use the Internet
  • Are literate enough to read and, at times, write
From there, you can compare demographics for people who meet those conditions. --Kainaw (talk) 20:05, 17 November 2006 (UTC)
Yes, that's all what I meant by "the obvious". Has anyone ever independently held an opt-in demographic study of users? I know such studies have been held of contributors, but never readers. -- Zanimum 20:47, 17 November 2006 (UTC)
Alexa Internet has some information on the subject here. Jon513 17:59, 19 November 2006 (UTC)

[edit] My syntax error in python-cgi-call

I call the following cgi from an html-form successfully but I get the plain-text. Then I change plain to html in the Content-type, I get an error message. This is the listing:

#!/usr/bin/python
print 'Content-type: text/plain\n\n'
print '''<html><head><title>python-cgi</title></head><body>1234 Hello  and XYZ Goodbye.</body></html>'''

Be grateful if somebody could help. Thank you in advance. Twma 04:50, 17 November 2006 (UTC)

We found out that it is our local installation problem which has nothing to do with the code. This case is closed. Should I delete the whole thing now, or leave it? If anybody wants to delete this, it is ok to me. Twma 09:16, 17 November 2006 (UTC)
I fixed your formatting with <pre>, so you could see how to pose this question with the correct program text. --Tardis 15:23, 17 November 2006 (UTC)

[edit] Conversion from Double Byte to Single Byte

Hi I am facing an issue while designing a web-based application for a company in Japan. There is a field on a screen (HTML) which takes zipcode in double bytes. This zipcode has to be checked for existence in a database (IBM DB2 on OS/390) field, which is single byte. How can I do that? Do I need to write a routine that can convert double byte field to single byte? Is it possible in the first place?

Awaiting your reply thanks and regards Saurabh

You can always typecast it, assuming you're sure you won't lose data. --Wirbelwindヴィルヴェルヴィント (talk) 08:42, 17 November 2006 (UTC)
Japan has single byte zipcodes? I didnt even know Japan uses zipcodes, since my Japan Travel Guide mentiones address only of the "2-3-3 Otemachi, Chiyoda-ku, Tokyo" variety (thats address for Tokyo International Post Office btw). Also I couldnt find article on Japanese mail system (only got NTT but thats for telephones). Shinhan 20:30, 17 November 2006 (UTC)
See Japanese addressing system, though there's not much about postal code. --Kusunose 15:27, 19 November 2006 (UTC)
If I understood it correctly, the application is receiving the field on a UTF-16 or UCS-2 encoding, while the database most probably is using a single-byte encoding (probably either ASCII compatible such as ISO-8859-1, Windows-1252, UTF-8, EUC-JP, Shift-JIS, or many others, or one of the EBCDIC variants). What you want is probably a character set conversion library. --cesarb 12:09, 18 November 2006 (UTC)

[edit] Make and model

Does anyone know the make/model of this scanner. I've found the image, but I can't find anything else, so I can't search for a store that has it in stock. --Kainaw (talk) 14:36, 17 November 2006 (UTC)

CanoScan LiDE 500F ([1]). –Mysid 15:35, 17 November 2006 (UTC)
Thanks! Now I have two products to choose from. --Kainaw (talk) 15:38, 17 November 2006 (UTC)

[edit] Internet security

what are some freeware viral/firewall progams from the net? cuz i just got a cable modem, and can actually download some now...Is it Steak?<Xiaden's Homepage> 14:41, 17 November 2006 (UTC)

If you are using Windows, it has a free firewall. I think it came with that big XP second upgrade thing. --Kainaw (talk) 14:45, 17 November 2006 (UTC)
I ment besides things that might already be on my computer. I used to have something like awareness(as in a program, not a word...) for viral protection, till my all smart and powerful father decided to take it off the system(same for any sort of firewall programs)Is it Steak?<Xiaden's Homepage> 17:31, 17 November 2006 (UTC)
AVG has anti-virus and anti-spyware products you might be interested in. Then there is Avast might also interest you. As for firewalls, try ZoneAlarm. x42bn6 Talk 20:21, 17 November 2006 (UTC)
Comodo firewall is free - link - the rule creation is kinda cumbersome, but the firewall is great.--Frenchman113 on wheels! 15:51, 24 November 2006 (UTC)

[edit] Word isn't saving Autorecovery files

Hi,

I have a document I'm working on in MS Word 2003, and it likes to hang when I try to save the document. Not every time I save, just every so often (it doesn't follow any pattern I've been able to discern). However, whenever Word hangs and I restart Word, Autorecovery files never show up in the list of "Recovered documents" - I only get the option to open the file I myself most recently saved (termed "Original Document" by Word). This has happened a few times now (and of course, once is too often!), and during the most recent occurrences I have searched my computer for the .asd files *before* shutting down Word (I understand Word deletes these files when it shuts down). I've looked where they're "supposed" to be (in Application Data -> Microsoft -> Word) and at one point I changed the location where I want Word to save them (just so I can look for them more easily) but it appears that Word is just not saving any .asd files! I have Word set to save Autorecovery files every 2 minutes, and I have my folders set to show hidden and system files.

Any idea what's going on? I'm trying to save my document frequently to prevent losing information, but since saving is what makes Word hang, I end up losing data anyway... I've done lots of web searching on this but my problem seems rather unique.

Any help would be much appreciated!! Thanks, Teagirl was taken 17:23, 17 November 2006 (UTC)

I'm not familiar with Word2003 (I use Word2000), but my experience with the autorecover feature is that it activates the recovered file automatically when I open the most recent saved version. When I open the most recent saved version, it says 'a more recent version is available, do you wish to open that' or something. Is that not happening for you?
On another note, you can set the autosave to activate as frequently as every minute; you can change that feature under tools, options. I suggest you also check there to see if there is an autosave setting you can modify, or if the current settings illuminate you v/v your problem. And finally, I wonder if it's possible that this problem is a symptom of a serious hardware failure, like a largely-corrupted hard disk? Because it's odd, to say the least, to regularly hang your compy with a particular file, and also to have it fail to restore properly. Have you done a disk check/defrag recently? Have you tried saving the file to a floppy and seeing how that goes? Or to a different hard disk (if you have more than one installed)? Are your video settings appropriate to your system? Anchoress 17:44, 17 November 2006 (UTC)

Hi, it's the question-asker again... I have Word set to save Autorecovery files every 2 minutes (I just changed that to 1 minute in case that makes a difference!) but it doesn't actually appear to be saving those files - when I look in the folder where they're supposed to be stored, there's nothing there (and yes, I have my system set up to show me "hidden" files). When I restart Word after it hangs, it shows me the list of potential recovered files, but there are never "Autorecovery" files included in that list - it only offers me the most recently saved version (that one I most recently saved myself... but not the one I was in the process of saving when the hang occurred, grr!).

Everything else on my computer seems to be working fine, although yes I'm probably due for a defrag. The system is only a few months old... anyway, thanks for the feedback! Teagirl was taken 17:58, 17 November 2006 (UTC)

Well, that is really odd, especially if your system is so new. Have you checked out the Microsoft Knowledgebase? I wonder if it's a software bug that could be fixed with a patch? The thing is, even though everyone bitches about MSOffice, the truth is, very few things happen in the suite that are genuinely random and unpredictable; most things that seem like glitches are actually caused by either operator error or an adjustable setting.
Ultimately, you shouldn't have to put up with a) your AutoRecover not working properly, and b) a newish system failing to support your document editing without hanging. But in the meantime, if the AutoRecover isn't doing its job at 2 minutes, I wouldn't set it any shorter than that, but I'd just do a hard save (the keyboard shortcut is CTRL+S) very frequently. I'd also check the Knowledgebase, and try working with the file on a floppy or an alternate hard drive to see if the problem persists. Anchoress 19:32, 17 November 2006 (UTC)
Did you also check the "Always create backup copy"? Also try disabling Fast saves and Background saves. (all 3 are on the same tab) As for searching for *.asd files did you try looking everywhere on your C:? Maybe its just saving at a wrong place. Shinhan 20:39, 17 November 2006 (UTC)

[edit] 64-bit vs 32-bit CPUs -- inherently faster?

When comparing a 64-bit CPU vs. 32-bit CPU that have the same cache, clock speed, architecture, etc, does 'bitness' in itself make a chip faster? Is a 64-bit CPU twice as fast as a 32-bit? --24.249.108.133 18:27, 17 November 2006 (UTC)

They cannot have the same cache or architecture. A 64-bit CPU has 64-bit registers in the cache and architecture. Also, it can store 64-bit memory addresses. That translates to less memory swapping. It takes time to page swap memory, so less swapping means faster processing - if and only if your program will be swapping memory. --Kainaw (talk) 18:51, 17 November 2006 (UTC)
Correction, if and only if your program is designed to use 64 bit words. Else the same amount of swapping occurs between 64 bit and 32 bit cpus. But to answer your question, no, a 64-bit CPU is not inherently faster, but it can run specially adapted programs faster. --Wirbelwindヴィルヴェルヴィント (talk) 20:23, 17 November 2006 (UTC)
64-bit CPUs use more transistors to work with the larger numbers, not more time. Additionally, a 64-bit CPU has a wider path to memory, and can read and write to it at twice the raw rate given the same clock speed. This makes 64-bit technology a must in server applications where the majority of work the processor does is moving data around, rather than calculations. Droud 15:54, 24 November 2006 (UTC)
The CPU isn't any faster (in terms of how many things it does per second), but in some cases you can do some useful procedure in fewer operations with a more-bits CPU. To do that, a program has to be compiled with the new CPU in mind. These kinds of savings are usually minor, although for a few applications (perhaps involving great numbers of financial calculations in integers) the improvement can be substantial. Of course, with modern PCs the limits on performance are often set by the memory, not the computation; a CPU with more bits of address space can support more RAM, which means less swapping as Kainaw said. On the other hand, this can't help programs that already were not swapping, and the pointers needed for using the larger amount of RAM take up more space, which can hurt things. The ability to support more RAM (as well as handle larger integers) are the real reasons for wider processors; speed is sometimes added but sometimes taken away. --Tardis 21:07, 17 November 2006 (UTC)
Note that a 64 bit arithmetic operation will be inherently slower that a 32 bit op. So running code that only needs 32 bit register accuracy might even be a little slower on a 64 bit processor - all other things being equal.
1. 64-bit arithmetic (mentioned above) would help speeding up processing in the cases where large numbers are used.
2. 64-bit pointers (instead of 32-bit ones) take more memory space and more memory bandwidth, slowing down the processing.
3. When you design processors, often you start with a transistor budget. Each function you add to your processor uses a certain amount of die surface. Potentially, you'd gain more performance by adding some other feature to your design than by extending it to 64 bits.
So basically, the answer is: it depends. On the application (does it use data types larger than 32 bits, does it potentially use > 2-4 GB memory), the size of the architectures in question, and the computer system in general. TERdON 23:14, 17 November 2006 (UTC)
Thanks for your replies! Some responses area bit techie for me. So just to summarize -- all things being equal, the main difference between 64-bit and 32-bit CPUs is the amount of memory they can address -- not a 2X speed increase (even if the OS and apps were all 64-bit)? (My co-workers and me are stuck with this mindset from the old videogame days where a 16-bit system would be twice as powerful as an 8-bit NES. And by extension, 32-bit Playstation is a leap over 16-bit. But once things hit 32-bit, there's no longer a 2X increase in power in 64-bit? ). Sorry if I'm rambling  :) --68.103.154.140 06:48, 21 November 2006 (UTC)
Video game systems became 2x fast at least because everything on these systems changed from the ground up - CPU, RAM, bus width, GPU, and software. Software libraries and API's were compiled with new settings. You will currently not see an appreciable difference with hybrid unix or windows based systems because invariably there is a lower bit bottleneck with one or more parts of those systems. It's fine for video cards to advertise 128 or 256 bit but the electrons still have to flow along 32 bit busses to other components of the motherboard. Think of 64 bit as a 64 lane highway - then all of a sudden the cars have to move onto a 32 or even 8 lane highway. Sandman30s 08:42, 21 November 2006 (UTC)