473,569 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

size of a function

Can any one write a code to measure the size of a function in gcc or vc
++ ?

Feb 19 '07 #1
4 2384
asit dhal wrote:
Can any one write a code to measure the size of a function in gcc or vc
++ ?
What would you do with the answer [1], and why?

[1] To the question "what's the size of this function", not "Can anyone
write ...", to which the answer is clearly "yes", since
compiler-writers exist.

--
Chris "electric hedgehog" Dollin
Meaning precedes definition.

Feb 19 '07 #2
In article <11************ **********@a75g 2000cwd.googleg roups.com>,
asit dhal <pe********@gma il.comwrote:
>Can any one write a code to measure the size of a function in gcc or vc
++ ?
Maybe -- but not in standard C.

You haven't really defined what is included in "the size" of
a function. If the function has uninitialized static variables,
then do you include the size of the automatic-initialized-to-zero
region used? If the function has initialized static variables,
then do you include the size of the initialization block (which
might be in a completely different code segment and might happen
to merge initializations of multiple variables from different
functions)? On architectures that are not stack-oriented, do you
include the size of the caller save area? Does "the size" of
the function include any temporary non-heap (e.g., stack) required
for it to execute?

If an optimizer detects common code between the function and
a different function, it could merge the two paths together
as long as it had some method of determining when to split apart
again (and if the code was the tail end of the code, that might
just be the "return from subroutine" code.) When code overlaps like
that, which of the functions do you count the size against?

--
All is vanity. -- Ecclesiastes
Feb 19 '07 #3

"asit dhal" <pe********@gma il.comwrote in message
Can any one write a code to measure the size of a function in gcc or vc
++ ?
void fsize( void (*fptr)() )
{
unsigned char bigbuff[1024*32];
void (*tptr)() = ( void (*) ()) bigbuff;
int len;

for(len = 1024*32; len >= 0; len--)
{
printf("trying %d\n", len);
memcpy(bigbuff, fptr, len);
(*tptr)();
}
}

There's a sporting chance that the this will print out values until it
segfaults. The last value is the size of your function.

When the
Feb 19 '07 #4
On Feb 20, 9:53 am, "Malcolm McLean" <regniz...@btin ternet.comwrote :
>
void fsize( void (*fptr)() )
{
unsigned char bigbuff[1024*32];
void (*tptr)() = ( void (*) ()) bigbuff;
int len;

for(len = 1024*32; len >= 0; len--)
{
printf("trying %d\n", len);
memcpy(bigbuff, fptr, len);
(*tptr)();
}

}

There's a sporting chance that the this will print out values
until it segfaults. The last value is the size of your function.
Not really, the second and subsequent memcpy's will have no effect.
You would do better (?) to memset the rest of the buffer to 0 or
some trap value in each case.
>
When the
Been trying your program out?

Feb 20 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
7534
by: Matthias | last post by:
Hi, I am just reading that book by Scott Meyers. In Item 4 Meyers suggests to always use empty() instead of size() when probing for emptyness of STL containers. His reasoning is that size() might take linear time on some list implementations. That makes sense at first. However, he also says this at the very beginning: "That being the...
1
1689
by: Timo | last post by:
All my font-sizes are set as relative sizes in CSS (large, medium, small, x-small, etc). Let's say something is set in CSS to be xx-large, but a visually impaired user wants it displayed even bigger. Can a script determine an element's absolute size, *as it is being rendered by the browser*, and then increment the element's font-size in...
18
2439
by: bsder | last post by:
Hi, Can anyone please tell me how to calculate the size of the following 4-dimensional array, and now to use qsort for sorting on this array? double sp = { 4.0, 5.0, 6.0 }; double spa = { { 4.0, 2.0 }, { 5.0, 8.0 }, { 6.0, 6.0 },
38
2343
by: maadhuu | last post by:
does it make sense to find the size of a function ??? something like sizeof(main) ??? thanking you ranjan.
20
1714
by: tigrfire | last post by:
I need the following code to return a string of character stored in array and also return the size of the array. I want to do it without using pointers and so far have the character storing working fine, it's just that I can't really think of a way to return the number of characters in the array. Anyone help me out? int inputPhrase() {...
4
3483
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a snippet from my .css file: *************************** body { margin:0; padding:0;
2
9642
by: yxq | last post by:
Hello I want to get Windows clipboard data size, seem to use the function "GetClipboardDataSize". Could anyone please tell how to do using vb.net? Thanks
7
8123
by: bowlderster | last post by:
Hello,all. I want to get the array size in a function, and the array is an argument of the function. I try the following code. /*************************************** */ #include<stdio.h> #include<stdlib.h> #include<math.h>
1
5441
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one group get automatically re-directed after uploading. However, this member group never gets the benefit of knowing if they've uploaded an incorrect...
6
1559
by: Marcolino | last post by:
Hi all, I have a simple problem but I don't know which is the best way to solve it. I need to savo into a table into access DB the location and the size of a form. Is there a way to save Location and Size into a single text field, on I need 4 Field X,Y,Height and Width? If yes, how can convert Location and Size into String and then Back to...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.