Query on Static function

Posted on 2006-03-29
Last Modified: 2010-04-15
Hi all,

Which one takes more memory a static function or a non static function and why?

Question by:arijit_rebaca
    LVL 24

    Expert Comment

    None, why should there be  a difference?

    LVL 3

    Expert Comment

    both will take the same memory
    non static variable might have a multiple occurance. but non static function will have only only one occurance.
    LVL 16

    Accepted Solution


    Generally, they will use exactly the same memory. However, there are obscure situations where they might end up different.

    In a library, a static function may take slightly less memory because since it cannot be accessed by the main program, it does not need to store its address anywhere else in the library.

    An optimiser can take advantage of its knowledge that a particular function is static to perform extra optimisation. For example, it it could remove some parameters from the stack frame and pass and return them in registers. It could also inline the function. Unfortunately, neither of these processes would predictably decrease the size of the function, and the inlining could actually increase the effective size.

    There may well be others I havent thought of.


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now