- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I define a local target variable inside a subroutine, then associate a global pointer to that value, is it safe to use the pointer to access that value outside of subroutine or the data can be overwritten and changed unexpectedly?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, if it is a local variable, it will disappear upon return from the routine. The exception is if that variable has the SAVE attribute.
What is the reason you want to do that? There are probably better methods, depending on the purpose.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, if it is a local variable, it will disappear upon return from the routine. The exception is if that variable has the SAVE attribute.
What is the reason you want to do that? There are probably better methods, depending on the purpose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As you know type components cannot be a target, i.e. property of a class cannot be a target.
on the other hand I need properties of numerous objects to be pointing to that specific property.
My temporary solution was to make a target in a subroutine and have the pointers to associated with that value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>on the other hand I need properties of numerous objects to be pointing to that specific property
Can the specific property in question .NOT. be an encapsulated property of some other object type? IOW all objects requiring said common property have pointers to the shared property.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
S. MPay wrote:
As you know type components cannot be a target, i.e. property of a class cannot be a target.
Component definitions cannot include TARGET, but any subobject of an object that has the target attribute is also a target.
Something associated with a pointer component is also always a target.
Perhaps you could elaborate further about the background to your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
jimdempseyatthecove wrote:
...Can the specific property in question .NOT. be an encapsulated property of some other object type?...
Dear Jim encapsulation is not a must. I am thinking to use a variable outside of target definition inside class module to workaround this. Maybe then even add a pointer type component associated with that variable inside type definition if needed.
ianh wrote:
...Perhaps you could elaborate further about the background to your question.
So my project has a Database class which keeps all the model information including an array of materials available.
We have numerous (say one million) elements but we have a few material types.
Each element has to be associated with a material.
I don't want to have one million instances of materials. So in my design each element has a material pointer which is associated with one of the materials in the Database%materialsArray.
Currently my only solution is to define materialsArray outside of the Database type as a target array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just give the Database object the TARGET attribute.
TYPE :: material_type ... END TYPE material_type TYPE :: database_type TYPE(material_type) :: materials(nm) ... END TYPE database_type TYPE :: element_type TYPE(material_type), POINTER :: material ... END TYPE element_type TYPE(database_type), TARGET :: Database TYPE(element_type) :: Elements(ne) ... Elements(ie)%material => Database%materials(im)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ianh wrote:
Just give the Database object the TARGET attribute.
TYPE :: material_type ... END TYPE material_type TYPE :: database_type TYPE(material_type) :: materials(nm) ... END TYPE database_type TYPE :: element_type TYPE(material_type), POINTER :: material ... END TYPE element_type TYPE(database_type), TARGET :: Database TYPE(element_type) :: Elements(ne) ... Elements(ie)%material => Database%materials(im)
I see, Thanks;
but the database is pretty big and contains many other types, and large arrays.
Making them all target won't affect calculation performance?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't know, as I don't know your code. But I rather doubt it.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page