CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: Size of something in bytes?

    Quote Originally Posted by TheGreatCthulhu View Post
    But, as Mutant_Fruit said, it is only the minimum amount of the required memory - there's no guarantee that the IntX type isn't using more. For example, the internal storage could initially be set to an amount that would be reasonable for most of the time (that could be way off from what your method would show for a particular value), and would only be incremented when required.
    if you read the original question:

    Quote Originally Posted by elitelogic View Post
    The sizeof operator will give me the size of the type, but that's not what I'm after. I need the size of the data in the variable.
    I interpret that to mean he is after how many bytes does the number occupy, which is what I provided.
    Last edited by MadHatter; September 25th, 2010 at 12:29 PM.

  2. #17
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Size of something in bytes?

    I think the OP is just not worded in a way that would be clear to everyone. It seems that what he is looking for is the number of digits in a numeric variable and unfortunately is referring to them as bytes causing confusion.

    As I mentioned, convert to string and check the length of that string and he will get the result that he is apparently looking for here.
    Always use [code][/code] tags when posting code.

  3. #18
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Size of something in bytes?

    Quote Originally Posted by MadHatter View Post
    I interpret that to mean [...]
    Quote Originally Posted by DataMiser View Post
    I think the OP is just not worded in a way that would be clear to everyone.
    Precisely - that's the the problem here: the question is not well formulated, most likely because, at the time it was asked, the OP didn't have a precise understanding of the relationship between the types and their values.

    So, people came up with different interpretations and offered different solutions.
    You also have to take note that the OP didn't say in what way exactly he would use this, so we can't draw any conclusions from that.
    For example, MadHatter's method could be perfectly valid if the OP needed to do some sort of quantization.

    Anyway, my point is, only the OP can tell us what is it that he's actually after here, provided that he himself has a good understanding of the topic.
    Last edited by TheGreatCthulhu; September 25th, 2010 at 02:38 PM.

  4. #19
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: Size of something in bytes?

    Quote Originally Posted by elitelogic View Post
    I know.

    In my original post, I said the sizeof operator will give me the sizeof the type. I know this.

    I'm not after the size of the int, or the double, or the long.


    I'm after the size of the variable that is 500 digits long.

    How long is that in bytes? I hope I'm being clear. My apologies for any confusion.
    I don't see any ambiguity here.

    He wants to know how many bytes an instance of IntX uses for a 500 digit number.
    My hobby projects:
    www.rclsoftware.org.uk

  5. #20
    Join Date
    May 2007
    Posts
    1,546

    Re: Size of something in bytes?

    Though I know i'm beating a dead dog here, I think i'll still respond one more time

    I'm not after the size of the int, or the double, or the long.
    I'm after the size of the variable that is 500 digits long.
    How long is that in bytes? I hope I'm being clear. My apologies for any confusion.
    That is very ambiguous and as written makes absolutely no sense. There are three ways this could be interpreted. I left rough estimates as to the memory costs at the end of each line.

    1) If i call "ToString()" on the number, i will end up with a string of 500 characters which will be 500 x sizeof (char) bytes in size. (1000 bytes)

    2) This could also be validly represented by 500 x sizeof (byte) which is smaller again by 50%. (500 bytes)

    3) It could also be represented by a handful of bytes. At a completely random guess, 10 bytes may be enough if you used standard binary notation. Someone else can do the math and work it out exactly. It'll be a lot less than 500 though. (about 10 bytes)

    So that's three ways to represent your number, each of which have different memory requirements. That's why this question is so ambiguous. Your question implies that you want either answer 1 or 2 but it's impossible to tell so rather than argue uselessly about it I'll leave it at this
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

  6. #21
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Size of something in bytes?

    Quote Originally Posted by Zaccheus View Post
    I don't see any ambiguity here.

    He wants to know how many bytes an instance of IntX uses for a 500 digit number.
    And, in addition to what Mutant_Fruit said, if you assume that IntX dynamically adapts memory-wise, you can also interpret the question as: "What is the amount of memory used by an IntX instance to represent a certain number?".

    But, (1) this is totally dependent on the actual implementation, and (2): what makes you think that the answer to this question would always be the same, even when calling the hypothetical "GetSize()" method once, and then calling it again only few lines later?

    Consider this: two IntX objects could contain the same value, but if the "usage-history" had been different, the memory requirements may have been different also, so the two instances would use different amount of bytes to represent the same number. (Again - depending on the implementation.)

    Furthermore, if you interpret this as the minimum amount of bytes required to represent an n-digit long number, then you can get the answer mathematically - you don't need to bother with the IntX type or it's instances and values at all.

    Quote Originally Posted by Zaccheus View Post
    It sounds like this is something the class itself would need to provide, because there really is no way for you to know how the type is implemented.
    Again, I think that the implementation details are open-source, but otherwise you're right - this should be the responsibility of the class, in which case the documentation would define what exactly the number returned by my hypothetical "GetSize()" method means.

  7. #22
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: Size of something in bytes?

    Quote Originally Posted by TheGreatCthulhu View Post
    what makes you think that the answer to this question would always be the same, even when calling the hypothetical "GetSize()" method once, and then calling it again only few lines later?
    Quote Originally Posted by TheGreatCthulhu View Post
    this should be the responsibility of the class, in which case the documentation would define what exactly the number returned by my hypothetical "GetSize()" method means.
    I completely agree - there would need to be a method which reports how much memory (in bytes) a specific instance of the class is actually using at any moment in time.
    Last edited by Zaccheus; September 26th, 2010 at 11:30 AM.
    My hobby projects:
    www.rclsoftware.org.uk

  8. #23
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: Size of something in bytes?

    "the number of bytes an X digit number is" sounds like the way oracle stores numbers. its' a feasible question, but due to the way most of us think of number systems, its quite different.

  9. #24
    Join Date
    Sep 2010
    Posts
    6

    Re: Size of something in bytes?

    My apologies for the slow reply but I wanted to close the loop on this in case others in the future have a similar question. Yes, my question was worded in a manner that instantly muddied the water and caused a lot of confusion.

    Zaccheus had it right when he said:
    He wants to know how many bytes an instance of IntX uses for a 500 digit number.
    The answer is that the IntX class has a method called "GetInternalState()" which provides the answer I was looking for.

  10. #25
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Size of something in bytes?

    Tada!

    (@OP: You can mark the thread as resolved by clicking the "Thread Tools" menu at the top and selecting "Mark Thread Resolved")

Page 2 of 2 FirstFirst 12

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

Featured