473,385 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2284
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 incomprehensible. 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.googlegr oups.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
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...
89
by: Sweety | last post by:
hi, Is main function address is 657. its show in all compiler. try it & say why? bye,
3
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...
41
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...
12
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
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...
54
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
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
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...
32
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.