Thread: Get the size of a generic type

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Oh no, if you have the size, it's no problem at all. The computer memory is just raw bytes - the computer itself doesn't care about the type. The compiler only does to simplify things for YOU, the programmer.
    You can allocate a certain number of bytes with type char, then use things such as memcpy to copy over the contents of the old memory.
    I can't say exactly how because I don't understand exactly what you're trying to do.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    uh oh
    Join Date
    Jan 2005
    Location
    Ontario, CA
    Posts
    66
    I haven't used this before myself, however, I just came across an interesting function provided in the malloc.h header. You can check it out here: _msize. By passing this function a pointer from an already dynamically allocated memory block (using malloc, calloc, realloc, etc) you can get the size of that allocated memory block (in bytes) utilizing this function.

  3. #18
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by cyreon View Post
    I haven't used this before myself, however, I just came across an interesting function provided in the malloc.h header. You can check it out here: _msize. By passing this function a pointer from an already dynamically allocated memory block (using malloc, calloc, realloc, etc) you can get the size of that allocated memory block (in bytes) utilizing this function.
    However, it is a Microsoft-specific extension.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #19
    uh oh
    Join Date
    Jan 2005
    Location
    Ontario, CA
    Posts
    66
    Thanks for pointing that out grumpy, good thing too since I was planning on actually using it now that I was aware of its existence.

  5. #20
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by cyreon View Post
    Thanks for pointing that out grumpy, good thing too since I was planning on actually using it now that I was aware of its existence.
    Usually things starting with an underscore are compiler specific.

    BTW, are there a lot of Canadians in Ontario, CA?
    That really confused the hell out of me when I received a package from there, until I figured out the CA meant California not Canada.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  6. #21
    uh oh
    Join Date
    Jan 2005
    Location
    Ontario, CA
    Posts
    66
    Quote Originally Posted by cpjust View Post
    Usually things starting with an underscore are compiler specific.

    BTW, are there a lot of Canadians in Ontario, CA?
    That really confused the hell out of me when I received a package from there, until I figured out the CA meant California not Canada.

    Ontario is a Canadian province and CA is actually Canada. So yes there are a lot of Canadians here Though I don't know of an Ontario in California, it could exist.

  7. #22
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by cyreon View Post
    Ontario is a Canadian province and CA is actually Canada. So yes there are a lot of Canadians here Though I don't know of an Ontario in California, it could exist.
    LOL! OK, well here's the Ontario, CA I thought you were talking about.
    I wonder how many other cities there are in California named after Canadian provinces?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  2. Little Array Difficulty
    By G4B3 in forum C Programming
    Replies: 16
    Last Post: 03-19-2008, 12:59 AM
  3. Help specifying a specific size type in C++
    By indigo0086 in forum C++ Programming
    Replies: 23
    Last Post: 06-12-2007, 10:51 AM
  4. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM
  5. Replies: 11
    Last Post: 03-25-2003, 05:13 PM