Solved

Importance of Private/ Importance of type...

Posted on 2004-09-02
7
230 Views
Last Modified: 2010-05-02
hello experts, this is maybe a juvenile type of question, but here goes...

i'm wondering what the effect of using Private versus Public function has on the compiled EXE... does using Private make the program smaller, or use less memory?  or does using Public when not needed somehow increase the possibilty of the program being hacked... somehow using the program to gain access to something they shouldn't be allowed?

also along the same lines... i'm wondering if declaring your variables as a specific type will effect the efficiency of the program... does declaring everything as varient type use more memory?  does declaring a variable as Long when it could have been Integer use more memory once my EXE is compiled?
0
Comment
Question by:RobK6364
7 Comments
 
LVL 10

Assisted Solution

by:kiranghag
kiranghag earned 25 total points
ID: 11969740
>>does declaring a variable as Long when it could have been Integer
>>use more memory once my EXE is compiled?
yes..
but this will be noticeable only when you use huge number of variables...or larger arrays
long variables require double the space than an integer.
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 25 total points
ID: 11970146
>>does using Private make the program smaller, or use less memory?  
I don't think so.  Public and Private have to do with the visibility of the function from other forms or modules.

>>using Public when not needed somehow increase the possibilty of the program being hacked
I don't think so.  Public is really only used by the compiler.  It might if you  provided your program in a library that someone could link in to their program and try to use it but they would still need to know function names and the like.

mlmcc
0
 
LVL 7

Assisted Solution

by:_agj_
_agj_ earned 25 total points
ID: 11970683
variant types DO use up a lot of memory....use them ONLY when specifically required.

the same goes for long etc.

As for Private/Public...it only affects visibility in code, not the exe efficiency or size.
It might affect it if u are compiling to p-code. But if u compile to native assembly, there is no reason u shud have any difference.

Regarding hack-ability, declaring something as public only makes it callable...which makes it less secure/exposed to the outside world. In that sense, expose as public only your required functions. Everything that is supposd to be 'internal' and 'non-exposed' should be private.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

by:martin_watts
ID: 11970938
>>>>does declaring a variable as Long when it could have been Integer
>>>>use more memory once my EXE is compiled?
>>yes..
on the other hand, performance wise, using long integers (32 bits wide, "LONG" in VB) is more efficient than using short integers (16 bits wide, "INTEGER" in VB). This is because almost all processors these days are 32 bit, and internally have to convert a 16 bit integer to a 32 bit integer before processing it. Difference in VB is marginal however.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 50 total points
ID: 11971027
The reason for having both Private and Public is for the benefit of the programmer. It would be possible to have all your variables (and procedures) declared as Public, but you could easily lose track of what is modifying the value of public variables. So, as a rule of thumb, keep the scope of variables a small as possible, if necessary passing them into procedures as parameters. This does use more resources, but the effect on performance would only be marginal.

I take the same attitude to declaring the type of variables. You can save a bit of time by not declaring them, but if do you declare your variables as their intended type, then you will know sooner when you have made an error. I always have Option Explicit in the Decalarations section of the code. You can ensure that it's put there automatically: Tools/Options..., Editor tab, Require Variable Declaration checkbox.
0
 
LVL 1

Author Comment

by:RobK6364
ID: 11993229
thanks for all the replies... most of my program is "optimized" with the correct declarations..but going back finding and changing things that already work but could be "optimized" would be a pain... so basically i just wanted to get a feel for if that was a very important thing to do...

and although there seem to be some varying opinions, it seems to not be any huge concern as long as my entire program isn't all variant, which it's not.

not sure who to give the points to... so i'll split em up
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 11993573
Glad I could help

mlmcc
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now