Kristoffer,

As for memory management, the modifyField! routines in the package should 
be OK.  If all the fields of the underlying immutable type are bits-types, 
then modifyField! does not need any heap allocation (at least not according 
to my experiments).  All the modifying and copying happens on the stack or 
in the registers.

A more difficult question is whether the compiler can eliminate the 
redundant copying (i.e., if b.field1 is a temporary copy of a.field1, and 
later b.field1 is copied back into a.field1, can the compiler elide both 
copying operations?) I am not able to tell from the code_native and 
code_llvm printouts whether the compiler is able to elide the extraneous 
copying in modifyField! due to my limited knowledge of LLVM and Intel 
machine language.

-- Steve Vavasis


On Monday, June 1, 2015 at 6:44:29 PM UTC-4, Kristoffer Carlsson wrote:
>
> Does anyone know how smart the compiler is when it comes to memory 
> management for things like what this package achieves? When you update a 
> field, will it just (naively) reallocate memory for a new type or will it 
> use the already allocated memory for the previous one? I guess the compiler 
> needs to prove that it is safe to reuse the memory which might be 
> difficult(?)
>
> One of the main things I lack in julia is basically type immutable types. 
> I want to be able to densely pack array of types while still being able to 
> change their values. One application for this is densely packed mutable 
> fixed size arrays. As far as I know, this is impossible right now?
>
>
>
>
>
>
> On Monday, June 1, 2015 at 11:57:19 PM UTC+2, Simon Byrne wrote:
>>
>> That's some impressive metaprogramming. In v0.4, you should be able to do 
>> this without the "maker" functions, using generated functions
>>
>> http://julia.readthedocs.org/en/latest/manual/metaprogramming/#generated-functions
>>
>> As far as an interface goes, I would suggest a macro, e.g. so that the 
>> user could write something like
>>
>> @modify! a[i].field = new
>>
>>
>> On Monday, 1 June 2015 03:09:29 UTC+1, [email protected] wrote:
>>>
>>> Following up on an earlier discussion that I started in this newsgroup, 
>>> I have written a small package that provides a routine to modify a field of 
>>> an immutable object in the case that the object is inside a container. 
>>>  Please refer to:
>>>
>>> https://github.com/StephenVavasis/Modifyfield.jl 
>>> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2FStephenVavasis%2FModifyfield.jl&sa=D&sntz=1&usg=AFQjCNEMQeocqbzVy4CBDgPjAQNZhmq8Fg>
>>>
>>> Feedback is welcome.
>>>
>>>
>>>

Reply via email to