I’m trying to make a:
immutable New_String_Type <: AbstractString
first::UInt64
last::Union{String, UInt64}
end
This works, but really I want this to take 128 bits. Is that what happens and/or can I do:
immutable New_String_Type <: AbstractString
first::UInt64
last::String
end
And reinterpret the memory to overwrite first and last (I assume last is a 64-bit pointer), and expect the GC to overlook invalid pointer when I overwrite?
Is this somehow better?:
immutable New_String_Type <: AbstractString
first::UInt64
last::Union{Vector{UInt8}, UInt64}
end
julia> @edit a=String("P")
ERROR: expression is not a function call, or is too complex for @edit to analyze; break it down to simpler parts if possible
in error(::String) at ./error.jl:21
I can locate, but is there a workaround for @edit
here?
I see alignments, and jl_value_t (at least 16-byte, didn’t read carefully…) that I assume is an overhead for all objects, that is the target of the String pointer (not immutable itself).
http://docs.julialang.org/en/latest/devdocs/object.html
#define JL_SMALL_BYTE_ALIGNMENT 16
#define JL_CACHE_BYTE_ALIGNMENT 64
#define GC_MAX_SZCLASS (2032-sizeof(void*))
STATIC_INLINE jl_value_t *jl_gc_alloc_(jl_ptls_t ptls, size_t sz, void *ty)
{
const size_t allocsz = sz + sizeof(jl_taggedvalue_t);
if (allocsz < sz) // overflow in adding offs, size was "negative"
jl_throw(jl_memory_exception);
jl_value_t *v;
if (allocsz <= GC_MAX_SZCLASS + sizeof(jl_taggedvalue_t)) {
int pool_id = jl_gc_szclass(allocsz);
jl_gc_pool_t *p = &ptls->heap.norm_pools[pool_id];
int osize;
if (jl_is_constexpr(allocsz)) {
osize = jl_gc_sizeclasses[pool_id];
}
else {
osize = p->osize;
}
v = jl_gc_pool_alloc(ptls, (char*)p - (char*)ptls, osize);
}
else {
v = jl_gc_big_alloc(ptls, allocsz);
}
jl_set_typeof(v, ty);
return v;
}
JL_DLLEXPORT jl_value_t *jl_gc_big_alloc(jl_ptls_t ptls, size_t sz)
{
[..]
size_t allocsz = LLT_ALIGN(sz + offs, JL_CACHE_BYTE_ALIGNMENT);
if (allocsz < sz) // overflow in adding offs, size was "negative"
jl_throw(jl_memory_exception);
bigval_t *v = (bigval_t*)malloc_cache_align(allocsz);
JL_DLLEXPORT void *jl_gc_managed_malloc(size_t sz)
typedef struct _jl_value_t jl_value_t;
struct _jl_taggedvalue_bits {
uintptr_t gc:2;
};
struct _jl_taggedvalue_t {
union {
uintptr_t header;
jl_taggedvalue_t *next;
jl_value_t *type; // 16-byte aligned
struct _jl_taggedvalue_bits bits;
};
// jl_value_t value;
};
//struct jl_taggedvalue_t <>;
union {
uintptr_t header;
struct {
uintptr_t gc:2;
} bits;
};
// must be 64-byte aligned here, in 32 & 64 bit modes
} bigval_t;
STATIC_INLINE void gc_time_count_mallocd_array(int bits)
{
(void)bits;
}