|
Hi, everyone!
Sometimes we use pointer as the parameter type and sometimes
we use reference as the parameter type.
I think using reference is better than using object directly.
Since it can save memory and operation (assignment operator).
But what about pointer V.S. reference? I want to know in which
case should I use pointer and in which case should I use reference.
Here are two samples,
Using reference,
--------
ostream& operator << (ostream&, ObjectType);
--------
Using pointer
--------
MemPoolAddSize (char*, size_t)
--------
I want to know your suggestions about pointer v.s. reference.
What is the general consideration about when using pointer and
when using reference?
Thanks in advance,
George
|
|
|
|
|
I use a rule from Scott Meyers: if the referenced-to object must always exist, use a reference; if you want to allow for a non-existing reference (NULL), use a pointer. Note that in your case the only way to use C strings is through a pointer to char.
|
|
|
|
|
That's a very good description!
Scott Meyers rules I like his books
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
Yes, I agree!
George
|
|
|
|
|
Thanks, João buddy!
What means "if you want to allow for a non-existing reference
(NULL), use a pointer" in your reply?
regards,
George
|
|
|
|
|
It means that if you want to allow NULL argument for your function (which means "no object"), use a pointer. The reference-based function argument requires you to pass an existing object and not the NULL value.
Happy Easter!
BB
|
|
|
|
|
Thanks, Bartosz buddy!
George
|
|
|
|
|
I want to implement an object pooling scheme for one of my C++ classes that are created and deleted frequently (so much as to cause a performance degradation). I am thinking about creating a pool and keep it in a static list, and manage the list instead of actually calling new and delete every time.
Is this recommended for improving performance OR is there a better alternative apporach?
My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Some of our intense code uses object pooling, and in our case it definately improves performance. We have a log and it will show that the object pooling removed the need for thousands upon thousands of calls to new (these are comm message objects, which would get created and deleted quite frequently when comm is heavy). The key is finding the right number of objects to store in your pool, so that you aren't using too much unnecessary memory, and so that your pool doesn't run out all the time. It will probably take some tuning.
If you are wary of it, then just try implementing it (it shouldn't be too bad). If profiling shows significant performance gains, it would be a good idea for you. As for alternative approaches, I don't really know of any off the top of my head.
Chris Richardson
You can stash and you can seize
In dreams begin, responsibilities U2 - Acrobat[^]
Stop being PC and accounting for everyone and his momma's timeframe. Just enjoy your - Rohit Sinha in the content-challenged thread
|
|
|
|
|
Thank you very much for the reply.
I made one implementation already. My objects are very small and the number of objects that are in memory at any time is not significantly high. To my surprise, my application improved more than 20% in performance. I am planning to post an article this weekend with the code.
Currently, the pool grows to the maximum number of objects of the class that have ever been in memory. I want to put in some code to release some of these objects, if they are not being used. Anyway. it is not important to me at this moment because memory usage is not very huge.
Thomas
My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Sounds good. 20% is a nice gain, and I look forward to your article.
Chris Richardson
You can stash and you can seize
In dreams begin, responsibilities U2 - Acrobat[^]
Stop being PC and accounting for everyone and his momma's timeframe. Just enjoy your - Rohit Sinha in the content-challenged thread
|
|
|
|
|
To disable ctrl-alt-del I use the following code but it is not working in windows 2000. So how to do it????
BOOL c=TRUE;
BOOL ret=SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,1,&c,0);
|
|
|
|
|
I do not know if it is still possible. What you could do is set a keyboard hook [^]. But it is usually not really user friendly to mess up with ctrl-alt-del
~RaGE();
|
|
|
|
|
In windows NT 4.0 and above you need to replace the MSGina.dll (handles windows login) with a new one. See GINA in MSDN.
GINA
A Graphical Identification and Authentication dynamic-link library (DLL). The GINA is a replaceable DLL component that is loaded by the Winlogon executable. The GINA implements the authentication policy of the interactive logon model and is expected to perform all identification and authentication user interactions.
When logged on, if a user enters a secure attention sequence (SAS), the user is presented with a security options screen. Among the options listed are:
Shut down the system.
Log off.
Change the password.
Go to the task list.
Lock the workstation.
A replacement GINA can provide similar options when an SAS event is received while a user is logged on.
secure attention sequence
(SAS) A key sequence that begins the process of logging on or off. The default sequence is CTRL+ALT+DEL.
John
|
|
|
|
|
How to block Window key and Alt key operation
|
|
|
|
|
|
|
After changing to Visual Studio.Net and C++ V7 (and from WinNT to Win2K), I cannot change the application icon of my Visual C++ 7.0 application.
On my developer machine, I can only see the standard MFC icon, although this was explicitly removed from the app's resources.
When the application is installed on another machine, it correctly displays its custom icon.
Any ideas ? Thank you !
|
|
|
|
|
If you move your .exe out of the release directory, is the icon still wrong ?
~RaGE();
|
|
|
|
|
Yes, in the app. The desktop link (I made one) displays the correct icon !
|
|
|
|
|
The desktop link uses the 32*32 icon, whereas the app (in the explorer) uses the 16*16 one. Did you change both of them (Check that ComboBox in the ressource editor...)
~RaGE();
|
|
|
|
|
1. Have you Rebuilt All?
2. In Doc/View architecture, distinguish between application and document icon (the link may display custom application icon, and the document icon may still be wizard-generated.
Regards,
BB
|
|
|
|
|
(1) Yes, I rebuilt
(2) It is not the problem with app/doc icon, but the app has the MFC default icon.
|
|
|
|
|
I think I had such problem once, but I can't remember clearly what the cause exactly was. You may try deleting all compiler-generated stuff (Debug\ and Release\ dirs, .aps, .ncb ...) and unused resource IDs, then build again.
Happy Easter!
BB
|
|
|
|
|
When editing the icon, did you replace every device type? If you don't know what I'm talking about, when editing the icon there is a combobox labeled device. Icons can have different sizes and color depths. Make sure to change them all.
Joel Lucsy
|
|
|
|