473,587 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Too Many Function Pointers?

C/C++ Compiler encourages to limit 1,000 functions under function
pointer, but I am allowed to overlimit 4,096 functions. I am just for fun
to test how it works.
The problem is that source code can only limit 64K lines otherwise C/C++
Compiler will fail to compile. It can't be done in static, but it can be
done at run-time to save source code's space.
I wrote ten sample functions. I did allocate function pointer into
memory at run-time (256K memory space). Then for...loop copies one of ten
sample functions' memory address into function pointer 65,536 times.
Function Pointer is now contained 65,536 functions into memory. Another
for...loop did execute all 65,536 functions through function pointer using
fprintf(...).
Text.Log is created from fprintf(...) has shown all executed 65,536
functions through function pointer. It works perfectly for larger project.
Can you please comment your opinion? Do you think it is too much
functions like overhead CPU? Try to compare to switch(...) because it can
only limit 32K or less. I believe that function pointer is the best
solution for great cache because most functions are smaller.

Bryan Parkoff
Dec 16 '05 #1
7 2291
Bryan Parkoff wrote:
C/C++ Compiler encourages to limit 1,000 functions under function
pointer, but I am allowed to overlimit 4,096 functions. I am just for fun
to test how it works.
The problem is that source code can only limit 64K lines otherwise C/C++
Compiler will fail to compile. It can't be done in static, but it can be
done at run-time to save source code's space.
I wrote ten sample functions. I did allocate function pointer into
memory at run-time (256K memory space). Then for...loop copies one of ten
sample functions' memory address into function pointer 65,536 times.
Function Pointer is now contained 65,536 functions into memory. Another
for...loop did execute all 65,536 functions through function pointer using
fprintf(...).
Text.Log is created from fprintf(...) has shown all executed 65,536
functions through function pointer. It works perfectly for larger project.
Can you please comment your opinion? Do you think it is too much
functions like overhead CPU? Try to compare to switch(...) because it can
only limit 32K or less. I believe that function pointer is the best
solution for great cache because most functions are smaller.

Bryan Parkoff


1. Your question is incomprehensibl e. Please see FAQ 5.8:
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
2. Compiler limitations are off topic here. Please ask in a newsgroup
dedicated to your compiler/platform
3. There is no such language as C/C++.

Dec 16 '05 #2
Bryan Parkoff wrote:
C/C++ Compiler encourages to limit 1,000 functions under function
pointer,
What? What are you talking about? 1000 functions under function pointer:
what does that mean? What "C/C++ Compiler" are you talking about? There
is no such language as "C/C++", you know that, right?
but I am allowed to overlimit 4,096 functions. I am just for fun
to test how it works.
The problem is that source code can only limit 64K lines otherwise C/C++
Compiler will fail to compile. It can't be done in static, but it can be
done at run-time to save source code's space.
You're losing me here...
I wrote ten sample functions. I did allocate function pointer into
memory at run-time (256K memory space). Then for...loop copies one of ten
sample functions' memory address into function pointer 65,536 times.
Care to illustrate this with code?
Function Pointer is now contained 65,536 functions into memory.
I honestly fail to understand what that sentence means. How can
a [single] function pointer (why is it capitalised in your message?)
"contain" 64K functions "into memory"? I've always been under the
impression that a single function pointer can only point to ("contain")
a single function. Or is "Function Pointer" a collection of some kind
in your explanation?
Another
for...loop did execute all 65,536 functions through function pointer using
fprintf(...).
Huh?
Text.Log is created from fprintf(...) has shown all executed 65,536
functions through function pointer. It works perfectly for larger project.
Uh... OK.
Can you please comment your opinion?
I have none. I don't know what you're talking about. If it were just me,
I'd probably not comment at all. But I am fairly certain that many others
didn't understand what you're talking about either.
Do you think it is too much
functions like overhead CPU?
Too much functions? Overhead CPU? No I don't think so.
Try to compare to switch(...) because it can
only limit 32K or less. I believe that function pointer is the best
solution for great cache because most functions are smaller.


You lost me. Smaller than what?

In any case, judging from my own (albeit somewhat obsolete, perhaps)
experience, it is much better to use broken C++ to explain something here
than broken English. I strongly suggest you try again, and this time post
some code to supplement your narrative.

V
Dec 16 '05 #3
Bryan Parkoff wrote:
C/C++ Compiler encourages to limit 1,000 functions under function
pointer, but I am allowed to overlimit 4,096 functions. I am just for fun
to test how it works.
Here is how I understand your question.

You are compiling for a platform which has some severe restrictions on
the size of code and data. The documentation for the compiler
encourages you to keep the program down to 1000 functions.

There are also limitations in the compiler. It can only accept up to
some 65,000 lines of source code in total, for some reason.

So you have tried a trick just for fun: you copied the compiled
function images into the data area, making lots of copies of them, just
to show that functions can live in the data area, and you can have lots
more of them there!

You want to know whether you can exploit this to perhaps write a loader
that will let you stuff more code into the system than can be compiled
into a single program?
Text.Log is created from fprintf(...) has shown all executed 65,536
functions through function pointer. It works perfectly for larger project.
The problem is that the functions are all the same, no? You want
thousands of unique functions, no? What's the point of having two
copies of the same function at two different locations?
Can you please comment your opinion? Do you think it is too much
In my opinion, what you are doing is beyond standard C++. You're
overcoming the limitations of a particular platform using various
hacks. They are not defined to work according to standard C++. So it's
best to discuss that with other users of the same platform, or an
appropriate development support forum or channel.
functions like overhead CPU? Try to compare to switch(...) because it can
only limit 32K or less. I believe that function pointer is the best
solution for great cache because most functions are smaller.


Whether using a table of function pointers, or using switch() is faster
is implementation-dependent. But if one technique produces code that is
too large, but another one fits, you can hardly compare them for
performance. The performance of a program that you can't compile or
load is nonexistent. :)

Dec 16 '05 #4

"Kaz Kylheku" <kk******@gmail .com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Bryan Parkoff wrote:
C/C++ Compiler encourages to limit 1,000 functions under function
pointer, but I am allowed to overlimit 4,096 functions. I am just for
fun
to test how it works.


Here is how I understand your question.

You are compiling for a platform which has some severe restrictions on
the size of code and data. The documentation for the compiler
encourages you to keep the program down to 1000 functions.

There are also limitations in the compiler. It can only accept up to
some 65,000 lines of source code in total, for some reason.

So you have tried a trick just for fun: you copied the compiled
function images into the data area, making lots of copies of them, just
to show that functions can live in the data area, and you can have lots
more of them there!

You want to know whether you can exploit this to perhaps write a loader
that will let you stuff more code into the system than can be compiled
into a single program?
Text.Log is created from fprintf(...) has shown all executed 65,536
functions through function pointer. It works perfectly for larger
project.


The problem is that the functions are all the same, no? You want
thousands of unique functions, no? What's the point of having two
copies of the same function at two different locations?
Can you please comment your opinion? Do you think it is too much


In my opinion, what you are doing is beyond standard C++. You're
overcoming the limitations of a particular platform using various
hacks. They are not defined to work according to standard C++. So it's
best to discuss that with other users of the same platform, or an
appropriate development support forum or channel.
functions like overhead CPU? Try to compare to switch(...) because it
can
only limit 32K or less. I believe that function pointer is the best
solution for great cache because most functions are smaller.


Whether using a table of function pointers, or using switch() is faster
is implementation-dependent. But if one technique produces code that is
too large, but another one fits, you can hardly compare them for
performance. The performance of a program that you can't compile or
load is nonexistent. :)

Hello,

Yes, it is what I mean. One function pointer has 256K bytes which
function has 4 bytes of memory address. It is 65,536 functions times 4
bytes equals 256KB. You can create 10 functions to 10,000 functions. Copy
member address of function into function pointer array. It is like "Run[0
to 65,535]()" function. You use for...loop to execute function pointer
65,536 times.

It is an example:

for (UINT Array = 0; Array < 65536; ++Array)
Run[Array]();

It will run fine. Why do document claim that it has to limit 1,000
functions. Someone wrote 80x86 assembly code and they attempted to
construct JMP Table up to 65,536, but it crashed. Function pointer table up
to 65,536 works fine under C/C++ code.
Do you believe that it is good program to handle 65,536 functions
through function pointer on 80x86 and other non-x86 machines?
Why do Microsoft C/C++ Compiler limits 64K source code lines? Do you
know if other C/C++ Compiler such as GNU have unlimited source code lines?
I am curious.

Bryan Parkoff
Dec 17 '05 #5
Ian
Bryan Parkoff wrote:
Why do Microsoft C/C++ Compiler limits 64K source code lines? Do you
know if other C/C++ Compiler such as GNU have unlimited source code lines?
I am curious.

Why on earth would you want a file with 64K lines?

Ian
Dec 17 '05 #6
Ian wrote:
Bryan Parkoff wrote:

Why do Microsoft C/C++ Compiler limits 64K source code lines? Do you
know if other C/C++ Compiler such as GNU have unlimited source code
lines? I am curious.

Why on earth would you want a file with 64K lines?


MS's MIDL generates them all the time, so I doubt that limit.

Maybe the restriction is on 64K functions. Darn.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Dec 17 '05 #7
Ian
Phlip wrote:
Ian wrote:

Bryan Parkoff wrote:


Why do Microsoft C/C++ Compiler limits 64K source code lines? Do you
know if other C/C++ Compiler such as GNU have unlimited source code
lines? I am curious.


Why on earth would you want a file with 64K lines?

MS's MIDL generates them all the time, so I doubt that limit.

Sounds like a good reason to avoid it...

Ian
Dec 17 '05 #8

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

Similar topics

3
3330
by: Markus Dehmann | last post by:
I have a class "Data" and I store Data pointers in an STL set. But I have millions of inserts and many more lookups, and my profiler found that they cost a lot of runtime. Therefore, I want to substitute the set<Data*> with a hash_set<Data*>: typedef hash_set<const Data*, hash<const Data*>, eqData> DataPointerHashSet; // typedef...
89
6441
by: Sweety | last post by:
hi, Is main function address is 657. its show in all compiler. try it & say why? bye,
3
2298
by: Dennis Chang | last post by:
Hi all, I was reading about function pointers and came across something which intrigued me. K&R2 calls qsort (pg.119) within main as so: qsort( (void **) lineptr, 0, nlines-1, (int (*) (void *, void*))(numeric ? numcmp : strcmp) ); I guess what interests me is the nameless function pointer and then the
41
10013
by: Alexei A. Frounze | last post by:
Seems like, to make sure that a pointer doesn't point to an object/function, NULL (or simply 0) is good enough for both kind of pointers, data pointers and function pointers as per 6.3.2.3: 3 An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.55) If a null pointer...
12
5451
by: Bill Pursell | last post by:
The following code generates a compiler warning when compiled with gcc -pedantic: typedef (*FUNC)(int); FUNC f; void * get_f(void) { return &f;
57
5620
by: Robert Seacord | last post by:
i am trying to print the address of a function without getting a compiler warning (i am compiling with gcc with alot of flags). if i try this: printf("%p", f); i get: warning: format %p expects type 'void *; but argument 2 has type 'void
54
24475
by: John | last post by:
Is the following program print the address of the function? void hello() { printf("hello\n"); } void main() { printf("hello function=%d\n", hello); }
4
2495
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
4
3499
by: Josefo | last post by:
Hello, is someone so kind to tell me why I am getting the following errors ? vector_static_function.c:20: error: expected constructor, destructor, or type conversion before '.' token vector_static_function.c:21: error: expected constructor, destructor, or type conversion before '.' token
32
5640
by: copx | last post by:
Why doesn't the C standard include generic function pointers? I use function pointers a lot and the lack of generic ones is not so cool. There is a common compiler extension (supported by GCC and lccwin32 for example) which I consider to be perfectly reasonable: you can cast every kind of function pointer to a void pointer and void...
0
7915
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
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...
0
8220
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
6619
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
5712
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
5392
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
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.