The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Function pointer to inline function ? emitrax High Level Programming 11 10-01-2009 04:59 AM
Return a value from called function to the calling function mvictorvijayan Shell Programming and Scripting 1 09-14-2009 05:19 AM
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 12:39 PM
Function within function (Recurance) chassis UNIX for Dummies Questions & Answers 2 09-19-2006 10:32 AM
How to convert the "select" function into a "poll" function rbolante High Level Programming 1 07-10-2001 11:49 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 10-26-2009
MrUser's Avatar
MrUser MrUser is offline
Registered User
  
 

Join Date: Oct 2009
Location: Earth
Posts: 23
Use of alloca function

Hello ,

i have read the manual page of alloca ,
it is documented there that "alloca works similar to the malloc but it allocates memory from stack and frees automatically".

i can't get how can i use that in a program .
if i'm not wrong can i use that like :


Code:
#include<stdio.h>
#include<alloca.h>
int main()
{
        void *p;
        p=alloca(20);
        if(p==NULL)
        {
                printf("alloca failed");
                exit(1);
        }
 
        strcpy(p,"Hello");
        printf("%s\n",p);
        printf("%u\n",p);
 
        return 0;
}

and what is the advantage of such a function.

even if i use array it also allocates memory from the stack and memory will be freed automatically.

what is the more advantage its having than array.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0