Memory Allocation (dare!)

This is a discussion on Memory Allocation (dare!) within the C Programming forums, part of the General Programming Boards category; hi i have some problem ... we have a function like below int how_many( int *p ){ ....... } how ...

  1. #1
    cof
    Guest

    Memory Allocation (dare!)

    hi
    i have some problem ...
    we have a function like below
    int how_many( int *p ){
    .......
    }
    how can we know the size of allocated memory for this pointer

    (
    for example in samewhere
    int *p=(int *)malloc(rand()*sizeof(int));
    printf("%d",how_many(p));

    there is a func. in VC named "_msize "
    but i want to learn how it works

    have a nice day

  2. #2
    Registered User Sargnagel's Avatar
    Join Date
    Aug 2002
    Posts
    166
    Just use Google or the Microsoft Developer Network to look up the function:

    http://msdn.microsoft.com/library/de...crt__msize.asp

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    The _msize function will return the size in bytes of the allocation. Remember if you are actually looking for the # of elements you must divide out by the size of a single element.

  4. #4
    cof
    Guest

    not exactly...

    ok
    i know _msize finds ...
    but i want to write my own function

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory allocation question
    By dakarn in forum C Programming
    Replies: 11
    Last Post: 12-01-2008, 10:41 PM
  2. Dynamic memory allocation...
    By dicorr in forum C Programming
    Replies: 1
    Last Post: 06-24-2006, 03:59 AM
  3. C memory allocation to c++
    By markucd in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2005, 04:56 AM
  4. Understanding Memory Allocation
    By Ragsdale85 in forum C Programming
    Replies: 7
    Last Post: 10-31-2005, 07:36 AM
  5. memory allocation ptr to array? how?
    By kokopo2 in forum C Programming
    Replies: 8
    Last Post: 09-01-2005, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21