Wikipedia:Reference desk/Archives/Computing/2014 January 8

Source: Wikipedia, the free encyclopedia.
<
Computing
Computing desk
< January 7 << Dec | January | Feb >> January 9 >
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.


January 8

Using input in JES.

I have 2 problems. I want to know how to utilise an input from the function requestString() in JES. I also want to know how to go about the addLine() function to a set of X,Y coordinates that have been set in an array of 10 each.

Much obliged if anybody can assist me on this. Smithy, 8/1/2014 Thesmithster (talk) 11:07, 8 January 2014 (UTC)[reply]

normal way to allow sentinel value in data

reading this Sentinel value, I wonder what the "normal" way is to use a sentinel value (no other form of data termination) but allow the sentinel value into the data. For example, a basically "null-terminated" string but which allows the null value to occur. For example (this doesn't actually work), you can escape the sentinel value with itself. So 1 null at the end is a termination, but two nulls are 1 \0 in the data (and then the data continues), three nulls are two \0's int he data (then the data continues), etc etc. Is this the normal way to solve this issue?--91.120.14.30 (talk) 11:29, 8 January 2014 (UTC)[reply]

In general, you make sure you use a character that's not valid in the data. The word "string" is usually reserved for referring to a sequence of printable characters, so zero can be used to terminate the string without ambiguity (the character '0' is not the same as the byte value 0). Similarly a sequence of ages or other positive numbers can be terminated by -1. If all possible byte values are admissible, you need to use a different approach, such as defining the string length explicitly (as in Hollerith constants). See also Escape character. Rojomoke (talk) 13:23, 8 January 2014 (UTC)[reply]
Another way to think about the problem is
Pascal string) have a "channel" for control that is explicitly distinct from the data. In those cases, it is trivially easy to distinguish the control signal. In-band signaling (with escape characters and sentinels) has some advantages for scalability and compactness, at the expense of some complexity. Nimur (talk) 15:14, 8 January 2014 (UTC)[reply
]
To my mind, there are basically four solutions to the string (list, array, etc.) termination problem:
  1. Don't use in-band terminators; they're often a bad idea anyway. Instead, use an out-of band mechanism, as Nimur described.
  2. Go ahead and use an in-band terminator; they're often a terrific idea. Just make very very sure that the terminator can never ever appear in normal data. (In the general case, therefore, you will often need to write code to check for stray terminator characters in data that you're writing, so that you can print a fatal error and abort or something, rather than writing an invalid file.)
  3. Use an in-band terminator, but with some way of escaping it if it must appear in the data. This is basically the case you were asking about. Doubling the terminator character is rare, in my experience, but not unheard of; in fact a doubled double-quote character is precisely how you typically represent a double-quote character in a quoted column in a
    TELNET protocol, which uses 0xFF (decimal 255) as an in-band escape character (and a doubled 0xFF0xFF to send an actual 0xFF); the rsh and ssh programs, which use ~ (at the beginning of a line) as an escape character (and a doubled ~~ if you want to send a single ~ character at the beginning of a line), and the screen program, which uses control-A (0x01) as an escape character, and control-A followed by a lower-case a if you want to actually send a control-A. (Which is a profound nuisance for us bash/emacs
    users, let me tell you, but that's another story.) So although I said that doubling a terminator to make it not a terminator is rare, we can see that doubling an escape character when you want a real copy of that character is pretty common.
  4. Use an in-band terminator (or an in-band escape character, for that matter), but forget to treat it specially, meaning that you occasionally create data files that either can't be read correctly, or crash when being read, or require elaborate heuristics in order to read, or in the worst case give your attackers a . So don't do that! (But anybody who's been in computing for very long has encountered at least one misbegotten system that does...)
Bottom line, if you're using in-band terminators or escape characters, you gotta think about this stuff pretty carefully. Thanks for doing so; I wish more programmers did. —Steve Summit (talk) 02:05, 9 January 2014 (UTC)[reply]
Thanks for this. In this case, let's say we double \0 to produce the \0 in data. So if you wanted your string to contain a \0 you would set it as: "In this string a \0\0 has been inserted by escaping it" where the final " of course inserts the \0 for you. So the data would be 'i', 'n', ' ', 't','h','i','s',' ',...'a', ' ', '\0', '\0', 'h', 'a', 's' ...'g', ' ', 'i', 't', '\0'. But the question is, how would this work in practice? When encountering a \0, how is it "safe" to read the next character to make sure it's not anotehr \0 to escape the first one? Also: what if the random data at the next address happens to start with \0? How do we deal with this? So you meant to terminate wtih \0 but the function keeps reading to see if you escaped it, and thinks you did (but you didn't, the next adddress just has \0 as its first value). What is the solution here? --91.120.14.30 (talk) 14:41, 9 January 2014 (UTC)[reply]
Right. Inspecting the random byte following the "real" terminator would not necessarily be safe -- and in any case that byte would not necessarily be non-zero! So if you used this technique, you would have to always explicitly write two terminating bytes: \0\1, or \0x, or \0 followed by anything other than \0. (So the string constant might be "In this string a \0\0 has been inserted by escaping it\0\1", although that gets you an extra "real" terminator at the end, which you could get rid of by saying char str[54] = "In this string a \0\0 has been inserted by escaping it\0\1", but that's obviously insane.) —Steve Summit (talk) 15:57, 9 January 2014 (UTC)[reply]
The term in computer science is
prefix-free code (or just prefix code). Encoding '\0' as two zero bytes and end-of-string as a single zero byte isn't prefix-free since the latter code is a prefix of the former. But, for example, using " for end-of-string, \" for a literal quote character, and \\ for a literal backslash is prefix-free. -- BenRG (talk) 22:06, 9 January 2014 (UTC)[reply
]

Purchasing RAM

According to this page, the two open RAM slots on my computer support DDR3-1066 and DDR3-1333. Does this mean they don't support other types of DDR3 RAM? What is the fastest type of RAM that I could purchase for the two open slots? Magog the Ogre (tc) 23:41, 8 January 2014 (UTC)[reply]

I recommend crucial.com to answer such questions. They download their tool onto your PC, do a system check, and make recommendations for upgrades. StuRat (talk) 00:08, 9 January 2014 (UTC)[reply]
StuRat, do you think it is safe to trust them? Thanks, --AboutFace 22 (talk) 03:08, 9 January 2014 (UTC)[reply]
Yes I do. I've used it on all my PCs. StuRat (talk) 03:11, 9 January 2014 (UTC)[reply]
Agreed. Crucial can be trusted. I use them a lot. 217.158.236.14 (talk) 11:54, 9 January 2014 (UTC)[reply]
Crucial is a brand of RAM. Their tool is safe to use, but be aware that they have the ulterior motive of promoting their brand, and that the tool isn't always correct—I've had it tell me that a laptop only supported 2 GB when it actually supported 4. I'm not sure this is relevant to the original question, though. -- BenRG (talk) 21:32, 9 January 2014 (UTC)[reply]
I don't think Crucial's diagnostic tool will help you. It will probably just tell you what you already found out from that web page. As far as I know, you can safely use faster DDR3 RAM in a motherboard that expects slower RAM, but I'm not 100% sure. Regardless, you won't get any speed benefit from it, so there's no reason to buy it unless it's cheaper. -- BenRG (talk) 21:32, 9 January 2014 (UTC)[reply]
The best way is the download the tech sheet for your motherboard and see what is officially supported. Sandman1142 (talk) 11:33, 13 January 2014 (UTC)[reply]