Thread: How do i use malloc?

  1. #1
    Registered User Josh Kasten's Avatar
    Join Date
    Jul 2002
    Posts
    109

    Question How do i use malloc?

    How do i use malloc?
    My program program crashes if i use it more than once.
    int a; don't make a program without it.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

  3. #3
    Registered User Josh Kasten's Avatar
    Join Date
    Jul 2002
    Posts
    109
    I can't find anything that tells me how to use it
    int a; don't make a program without it.

  4. #4
    Registered User dizolve's Avatar
    Join Date
    Dec 2002
    Posts
    68
    PHP Code:
    char *str;

    str = (char *)malloc(10); // str now points to a block of 10 bytes (error check this)

    free(str); // Free the memory

    str NULL// So we don't accidently cause a crash by accessing memory that we free'd 

      __               &n bsp;      ___ & nbsp;       &nb sp;       &nbsp ;    
     /\ \  __    &nbs p;           /\_ \      &nbsp ;        & nbsp;     
     \_\ \/\_\  ____     _ __\//\ \    __  __&n bsp;    __   
     /'_` \/\ \/\_ ,`\  / __`\\ \ \  /\ \/\ \  /'__`\ 
    /\ \_\ \ \ \/_/  /_/\ \_\ \\_\ \_\ \ \_/ |/\  __/ 
    \ \___,_\ \_\/\____\ \____//\____\\ \___/ \ \____\
     \/__,_ /\/_/\/____/\/___/ \/____/ \/__/   \/____/
            &n bsp; I have a BAD figlet& nbsp;addiction.

  5. #5
    Registered User Josh Kasten's Avatar
    Join Date
    Jul 2002
    Posts
    109
    ops i mean to say realloc
    int a; don't make a program without it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. malloc + segmentation fault
    By ch4 in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 03:46 PM
  2. Is there a limit on the number of malloc calls ?
    By krissy in forum Windows Programming
    Replies: 3
    Last Post: 03-19-2006, 12:26 PM
  3. Malloc and calloc problem!!
    By xxhimanshu in forum C Programming
    Replies: 19
    Last Post: 08-10-2005, 05:37 AM
  4. malloc and realloc
    By odysseus.lost in forum C Programming
    Replies: 3
    Last Post: 05-27-2005, 08:44 AM
  5. malloc() & address allocation
    By santechz in forum C Programming
    Replies: 6
    Last Post: 03-21-2005, 09:08 AM