473,386 Members | 1,815 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,386 software developers and data experts.

Question on passing a structure to a function

I have a structure

typedef struct t_abcd
{
int a;
int b;
int c;
} abcd;

I have to pass the structure to another function. I can do this in two ways.
1) I am passing this structure as shown
func()
{
abcd *ps;
ps = malloc(sizeof(abcd);
someFunc(ps);
}

2) i am passing this structure as shown
func2()
{
abcd *ps;
ps = malloc(sizeof(abcd);
someFunc(&ps);
}


The associated API's for these two calls would be
int someFunc( abcd *ps); /*For the first type of call*/
int someFunc(abcd **pq); /*For the second type of call*/

Could you guys please tell me which would have the faster access to and from the CPU? Assuming that this function is called 97 % of the time during execution of the module which contains this function
May 9 '07 #1
1 1728
DeMan
1,806 1GB
In both cases you are pasing a pointer (in the first to the structure, in the second to the pointer to the structure).

I would imagine passing the pointer is just as efficient both times, But I suspect (because you have to translate two pointers) that the second would take fractionally longer to access because you have to check two pointers.



(I think you may have meant the question to refer to
someFunc(*ps); (passing the Actual as in - struct int someFunc( abcd ps)
in the first instance which I would think would create a lot more overhead if you called this function frequently)
May 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: LG | last post by:
Just have a question with regards to the clipboard, and how to read what other applications (Adobe InDesignCS) place in the clipboard. I am currently in the process of creating a booklet from a...
27
by: Ted Lilley | last post by:
What I want to do is pre-load functions with arguments by iterating through a list like so: >>>class myclass: .... pass >>>def func(self, arg): .... print arg >>>mylist = >>>for item...
5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
2
by: Steve Turner | last post by:
I have read several interesting posts on passing structures to C dlls, but none seem to cover the following case. The structure (as seen in C) is as follows: typedef struct tag_scanparm { short...
14
by: Mr Newbie | last post by:
I am often in the situation where I want to act on the result of a function, but a simple boolean is not enough. For example, I may have a function called isAuthorised ( User, Action ) as ?????...
7
by: Jake Thompson | last post by:
Hello I created a DLL that has a function that is called from my main c program. In my exe I first get a a pointer to the address of the function by using GetProcAddress and on the dll side I...
6
by: RSH | last post by:
I am still trying to grasp the use of real world Objects and how to conceptualize them using a business scenerio. What I have below is an outline that I am wrestling with trying to figure out a...
7
by: Logan Lee | last post by:
ORIGINAL CODE: typedef struct StackStruct *Stack; typedef void *StackElt; StackElt top(Stack thisStack); ANOTHER CODE: typedef struct StackStruct Stack; typedef void *StackElt;
13
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper in C# for an SDK that has been supplied as a .LIB file and a .h header file. I have got most of the functions to work but am really struggling with the...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.