Are cfc's safe in the application scope [closed] - coldfusion

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm kind of new with cfml and I am trying to figure out if putting components in the application scope is okay, if everything in the component is var'd.
I know that scope is shared by all users but if all the variables are var'd in the functions would that prevent people from seeing each others data and/or race conditions?
Thanks

If the data you store in the component belongs to the whole application, like e.g. some page layout data, it is fine to store it in the application scope.
Also, if the component is stateless, i.e. all the variables in it are in the local scope, it is safe to store objects created from it in that scope.
Though if the component is stateful, i.e. it stores data from previous requests or user specific data in it, it is not safe to store objects created from it in the application scope, because this may cause data leakage and other unexpected and unwanted results due to race conditions or incorrect access.
In that case you should rather store your component in the session scope.

Related

Why would you use pointers for Low Memory Allocation? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
So I was looking at the source code of unreal engine and I came across this:
class USphereComponent* CollectionSphere;
There are using pointer for something that is going to be initialized and spawned once when the game begins and some objects will be overlapping it,I thought pointers are mainly used for more mid-high memory allocation purposes
So why are they using it now?
Keep in mind Im not really good at pointers so Im just trying learn and gather some information about it.
Whether to use pointers or not has almost nothing to do with "low" or "mid-high memory allocation purposes".
You use a pointer when you need a pointer, and often that's when the pointee (the thing being pointed to) will live for longer than an "automatic" object would in any of the program's existing, conveniently-accessible scopes.
Basically, *CollectionSphere will be a global (or something similar), but we can't construct it right away. The author has decided that they need fine control over the lifetime of the object. So, they have created a pointer to point to that object when the time comes.

Declaring instance without variable name c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
After asking C++ Error linking in consumer file caused by static data field, I tried two different declarations for an instance of StateConservator:
StateConservator cs(*pContainer, pDoc->GetConfiguration());
and
StateConservator(*pContainer, pDoc->GetConfiguration());
The first did what I want, it only passes on the destructor only after the end of the scope. The second passes on the destructor in the own line of the declaration itself.
Is the compiler behaving correctly? If it is the correct behavior what is the way to declare an anonymous variable in that line?
You cannot have "unnamed" objects in C++. In the second case, the object is created and destroyed instantaneously because it is not associated with a name. The association with a name (e.g., variable) gives an object scope which controls its lifetime. By not naming an object, it's lifetime is bound to the statement. If it is given a name, then it is bound to the scope that the name is declared in.

Is it possible to send a pointer to function via socket? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two processes of the same program, possibly running on two different machines.
I'd like the process P2 to receive a function pointer from process P1 via socket.
Is is possible? Is it a good practice?
EDIT: more interesting would be to send the code of the function too, but I'm skeptic about this. Would it be possible?
You can send a function pointer from one process to another, the same way you can send a pointer to some other object.
The problem is that the pointer may not actually point to the function as it exists in the target process. Especially if the OS is protecting itself with things like ASLR.
You could also send the code across, provided you had some way of figuring out where it ended, and that it was position independent code, and that your environment allowed you to write arbitrary data to memory and then call it.
But, to be honest, there are better ways to achieve what you seem to want, such as the use of RPC (remote procedure calls), in a more portable manner.

Can weakpointer be a substitute for mutex or critical section in synchronization issues [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I would like to know if Weak Pointers can be used against/instead of Mutex/Critical Sections for synchronization issues.
If the only synchronisation issue you've got is ensuring the object's still around when you'd like to access it, then getting a shared_ptr from a weak_ptr will ensure its lifetime is extended. It's only sufficient for very narrow scenarios though, for example - if a shared_ptr is stored in a container somewhere, and may be erased at any time but is otherwise unused, while your code with the weak_ptr may want to actually access or modify the data content of the object.
If you also need to protect against concurrent accesses during updates to the data in the object, then you need more than that shared_ptr....

C++ one singleton Application object [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This is basically what i am now using a lot in my application for accessing objects that needed to be accessed from many classes:
Application::getInstance()->getComponentList()
Still think that this is not the good way how to access objects that need to be shared among many classes.
Question is if there is better approach to share objects in big application.
I have to agree with you and juanchopanza: accessing objects via a single singleton object throughout an entire project is a poor practice since modules are supposed to have few and well-stated dependencies among them (ideally: interfaces or means of communication).
Also: it's easy to violate the single responsibility principle.
There's no "do X instead of the singleton approach" solution, or no silver bullet: sometimes a singleton can really be useful but if possible: avoid it and design a clear interface instead.
Also: there isn't enough information in your question to state something more specific.