|
-
Sep 1st, 2012, 07:43 AM
#1
"Cost" of calling a function
I am curious what the physical "cost" is of calling a function. What really happens to memory when that function is called.
Let's say I've got a complicated loop running in code - and I want to take the "contents" of that loop logic and put it in another C++ function.
If the "variables" and what-not (I've got large arrays and "strings" passed from "managed" code here as well) are all passed by REFERENCE - so no memory is copied for that what is other costs involved?
Is there a GOSUB-like or JSB-like statement in C++ that could help me visually organize this code without incurring the cost of calling functions??
Last edited by szlamany; Sep 1st, 2012 at 11:07 AM.
-
Sep 1st, 2012, 11:29 PM
#2
Re: "Cost" of calling a function
Moved to C++ Forum from C++ Codebank.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 2nd, 2012, 12:42 AM
#3
Re: "Cost" of calling a function
You might want to have a look at this and perhaps investigate further along that line.
http://www.codeproject.com/Articles/...with-the-stack
-
Sep 2nd, 2012, 07:22 PM
#4
Re: "Cost" of calling a function
Thank you - that was a great read.
I'm doing loops on 500,000+ byte chunks of memory representing the text of documents. Each character is passed through lots of conditions and also looked at against arrays of rules.
It's that moment of looking at the arrays of rules that I was thinking of removing to a separate function body - passing in whatever is needed by reference. I can see from that article how the stack builds up when that happens.
I was concerned because I was looking at it from the "outside" - where the big loop on the memory chunk is being done. But actually the amount of code running against the array of rules is huge and adding on some stack-framing requirements is most likely inconsequential to the run time.
Bottom line is I can benchmark and time this myself - and I probably should.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|