Results 1 to 4 of 4

Thread: Couple of questions

  1. #1

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Couple of questions

    1. In my book it says that a double uses 64-bits in an example then on the variable table it says it uses 8 bytes , i.e 32-bits, which is it ?

    2. Is memory structured into 1byte segments, so i.e you could say theres no such thing as a 32-bit number or 64-bit rather 8 * 1 byte storage space is need for an Long, double etc.. ?

    3. Would it speed anything up to convert a string to Unicode via code first then send it to the memory as a number or is it just as efficient letting Windows do it and does VB.NET have any function to do this ?

  2. #2
    Lively Member Shardox's Avatar
    Join Date
    Nov 2006
    Location
    Barcelona, Spain
    Posts
    123

    Re: Couple of questions

    8 bytes = 64 bits

  3. #3

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Couple of questions

    Quote Originally Posted by Shardox
    8 bytes = 64 bits

    doh!

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Couple of questions

    As for #3, it is much more efficient to let windows do it, and it ties into #2.

    While memory is a collection of bytes, and you can technically address any one of those bytes, in fact, memory is moved in and out of the processor in chunks for efficiency reasons. My knowledge on this is considerably dated, but think about it this way: If you have a 32 bit bus, so that the most efficient amount of memory you can move around is four bytes, then even if you want a single byte, there is no advantage to just getting that byte, you might as well get that byte....and the next three, and disregard the three you don't need.

    Since all processors since the 386 were 32 bit processors, then it was generally more efficient to move a 32 bit number into the registers on the processor. You could work with a byte, or a word (2 bytes), but neither one was as efficient. You actually had to do extra work to deal with just a byte or two. Therefore, moving four bytes at a time makes the most sense. However, I'm pretty sure that modern processors move much more than four bytes at a time into the on chip cache.

    As for a string, there isn't one. All there is is a four byte pointer to the first character. If the characters are stored sequentially (they are), and each character occupies two bytes (or 1 for ASCII), then you can find the address of any character by adding 2 x [character position] to the address of the first character. Thus, not only are you only moving numbers rather than strings, you are only finding individual characters by adding a number to a different number.

    Well, I've lost track of where I was going, but that's an overview. If you read pretty much any book on assembly language programming, for just about any processor, you will get a more detailed explanation of the same thing. How much memory is being moved on each read is not particularly relevant to VB programming, but it can be interesting.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width