September 01, 2022 Re: Classes on stack | ||||
---|---|---|---|---|
| ||||
Posted in reply to bauss | On Thursday, 1 September 2022 at 11:06:31 UTC, bauss wrote:
> On Thursday, 1 September 2022 at 10:51:44 UTC, Redwan wrote:
>> On Thursday, 1 September 2022 at 10:21:32 UTC, rikki cattermole wrote:
>>>
>>> On 01/09/2022 10:13 PM, Redwan wrote:
>>>> if it's for GC, how to completely disable gc? I don't Wan use it at all. I searched for a compiler command line disabling for gc but not found. GC.disable() is ugly way I think.
>>>
>>> As long as you want to use things like classes and Phobos, you're stuck with the GC being linked in and active at some point in the lifetime of your process.
>>>
>>> D's runtime includes a lot of infrastructure such as threading that is initialized before your main ever executes.
>>>
>>> You can limit the GC activity by things like GC.disable, but its still linked in and in use at some point in time.
>>>
>>> D's GC is your friend, if you don't allocate it won't attempt to collect unless you want it to.
>>
>> well I know it's my friend, but we're just friend :) I don't want to use it because it's uses alot of heap and I don't like it. my case is special and all of heap usages needs to be done by me. so I want to do something to avoid this dynamic and runtime linkages and etc and be pure and in my hand. definitely it must be some flags or configurations to disable this stuff for a system language. am I right?
>
> I already gave you the solution one message above; betterC (A subset of D) is what you want.
yes sorry, I saw and I was reading about it, thank you.
as I found, I can't use some important features in betterC. like classes. but I need them.
|
September 01, 2022 Re: Classes on stack | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Thursday, 1 September 2022 at 10:21:32 UTC, rikki cattermole wrote:
>
> On 01/09/2022 10:13 PM, Redwan wrote:
>> if it's for GC, how to completely disable gc? I don't Wan use it at all. I searched for a compiler command line disabling for gc but not found. GC.disable() is ugly way I think.
>
> As long as you want to use things like classes and Phobos, you're stuck with the GC being linked in and active at some point in the lifetime of your process.
>
> D's runtime includes a lot of infrastructure such as threading that is initialized before your main ever executes.
>
> You can limit the GC activity by things like GC.disable, but its still linked in and in use at some point in time.
>
> D's GC is your friend, if you don't allocate it won't attempt to collect unless you want it to.
the worst things about it is as I didn't start writing my code it already has memory leak :/
|
September 01, 2022 Re: Classes on stack | ||||
---|---|---|---|---|
| ||||
Posted in reply to Redwan |
On 01/09/2022 11:20 PM, Redwan wrote:
> the worst things about it is as I didn't start writing my code it already has memory leak :/
That's not what valgrind told you.
There is some state like the GC and threads that won't be deallocated until the end of process by the kernel.
Its not a memory leak, it is just long lived internal state.
|
September 01, 2022 Re: Classes on stack | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Thursday, 1 September 2022 at 11:24:38 UTC, rikki cattermole wrote:
>
> On 01/09/2022 11:20 PM, Redwan wrote:
>> the worst things about it is as I didn't start writing my code it already has memory leak :/
>
> That's not what valgrind told you.
>
> There is some state like the GC and threads that won't be deallocated until the end of process by the kernel.
>
> Its not a memory leak, it is just long lived internal state.
so with this state, how can I found memory leak in my program?
|
September 01, 2022 Re: Classes on stack | ||||
---|---|---|---|---|
| ||||
Posted in reply to Redwan |
On 01/09/2022 11:25 PM, Redwan wrote:
> so with this state, how can I found memory leak in my program?
Most people don't bother beyond valgrind in D.
Either its on the stack, GC allocated or reference counted for most people in D.
These three strategies pretty much guarantee no leaks (reference counting does have some pitfalls relating to data structures but we can safely ignore that here).
|
September 01, 2022 Re: Classes on stack | ||||
---|---|---|---|---|
| ||||
Posted in reply to Redwan | On Thursday, 1 September 2022 at 11:17:20 UTC, Redwan wrote:
> On Thursday, 1 September 2022 at 11:06:31 UTC, bauss wrote:
>> On Thursday, 1 September 2022 at 10:51:44 UTC, Redwan wrote:
>>> On Thursday, 1 September 2022 at 10:21:32 UTC, rikki cattermole wrote:
>>>>
>>>> On 01/09/2022 10:13 PM, Redwan wrote:
>>>>> if it's for GC, how to completely disable gc? I don't Wan use it at all. I searched for a compiler command line disabling for gc but not found. GC.disable() is ugly way I think.
>>>>
>>>> As long as you want to use things like classes and Phobos, you're stuck with the GC being linked in and active at some point in the lifetime of your process.
>>>>
>>>> D's runtime includes a lot of infrastructure such as threading that is initialized before your main ever executes.
>>>>
>>>> You can limit the GC activity by things like GC.disable, but its still linked in and in use at some point in time.
>>>>
>>>> D's GC is your friend, if you don't allocate it won't attempt to collect unless you want it to.
>>>
>>> well I know it's my friend, but we're just friend :) I don't want to use it because it's uses alot of heap and I don't like it. my case is special and all of heap usages needs to be done by me. so I want to do something to avoid this dynamic and runtime linkages and etc and be pure and in my hand. definitely it must be some flags or configurations to disable this stuff for a system language. am I right?
>>
>> I already gave you the solution one message above; betterC (A subset of D) is what you want.
>
> yes sorry, I saw and I was reading about it, thank you.
>
> as I found, I can't use some important features in betterC. like classes. but I need them.
Are you sure you need classes and can't do with structs?
|
September 01, 2022 Re: Classes on stack | ||||
---|---|---|---|---|
| ||||
Posted in reply to bauss | On Thursday, 1 September 2022 at 12:00:40 UTC, bauss wrote:
> On Thursday, 1 September 2022 at 11:17:20 UTC, Redwan wrote:
>> On Thursday, 1 September 2022 at 11:06:31 UTC, bauss wrote:
>>> On Thursday, 1 September 2022 at 10:51:44 UTC, Redwan wrote:
>>>> On Thursday, 1 September 2022 at 10:21:32 UTC, rikki cattermole wrote:
>>>>>
>>>>> On 01/09/2022 10:13 PM, Redwan wrote:
>>>>>> if it's for GC, how to completely disable gc? I don't Wan use it at all. I searched for a compiler command line disabling for gc but not found. GC.disable() is ugly way I think.
>>>>>
>>>>> As long as you want to use things like classes and Phobos, you're stuck with the GC being linked in and active at some point in the lifetime of your process.
>>>>>
>>>>> D's runtime includes a lot of infrastructure such as threading that is initialized before your main ever executes.
>>>>>
>>>>> You can limit the GC activity by things like GC.disable, but its still linked in and in use at some point in time.
>>>>>
>>>>> D's GC is your friend, if you don't allocate it won't attempt to collect unless you want it to.
>>>>
>>>> well I know it's my friend, but we're just friend :) I don't want to use it because it's uses alot of heap and I don't like it. my case is special and all of heap usages needs to be done by me. so I want to do something to avoid this dynamic and runtime linkages and etc and be pure and in my hand. definitely it must be some flags or configurations to disable this stuff for a system language. am I right?
>>>
>>> I already gave you the solution one message above; betterC (A subset of D) is what you want.
>>
>> yes sorry, I saw and I was reading about it, thank you.
>>
>> as I found, I can't use some important features in betterC. like classes. but I need them.
>
> Are you sure you need classes and can't do with structs?
I need inheritance and other OOP concepts and template features. does D's struct support them? as I found, No.
|
September 01, 2022 Re: Classes on stack | ||||
---|---|---|---|---|
| ||||
Posted in reply to Redwan | On Thursday, 1 September 2022 at 12:08:05 UTC, Redwan wrote:
>
> I need inheritance and other OOP concepts and template features. does D's struct support them? as I found, No.
There are ways to put classes on the stack (std.typecons.scoped, emplace()...), but not completely polymorphic classes.
In C++, polymorphic dynamic-dispatch objects are not value types either, you need the concrete type to put them on stack or risk slicing. They would typically be on the heap with `new` / `unique_ptr`.
So it's really the same constraints, if you have a capped maximum of what the child class will be, you can also emplace in a byte array on the stack any instance of the hiearachy.
|
September 01, 2022 Re: Classes on stack | ||||
---|---|---|---|---|
| ||||
Posted in reply to Redwan | On Thursday, 1 September 2022 at 12:08:05 UTC, Redwan wrote:
> On Thursday, 1 September 2022 at 12:00:40 UTC, bauss wrote:
>> On Thursday, 1 September 2022 at 11:17:20 UTC, Redwan wrote:
>>> On Thursday, 1 September 2022 at 11:06:31 UTC, bauss wrote:
>>>> On Thursday, 1 September 2022 at 10:51:44 UTC, Redwan wrote:
>>>>> On Thursday, 1 September 2022 at 10:21:32 UTC, rikki cattermole wrote:
>>>>>>
>>>>>> On 01/09/2022 10:13 PM, Redwan wrote:
>>>>>>> if it's for GC, how to completely disable gc? I don't Wan use it at all. I searched for a compiler command line disabling for gc but not found. GC.disable() is ugly way I think.
>>>>>>
>>>>>> As long as you want to use things like classes and Phobos, you're stuck with the GC being linked in and active at some point in the lifetime of your process.
>>>>>>
>>>>>> D's runtime includes a lot of infrastructure such as threading that is initialized before your main ever executes.
>>>>>>
>>>>>> You can limit the GC activity by things like GC.disable, but its still linked in and in use at some point in time.
>>>>>>
>>>>>> D's GC is your friend, if you don't allocate it won't attempt to collect unless you want it to.
>>>>>
>>>>> well I know it's my friend, but we're just friend :) I don't want to use it because it's uses alot of heap and I don't like it. my case is special and all of heap usages needs to be done by me. so I want to do something to avoid this dynamic and runtime linkages and etc and be pure and in my hand. definitely it must be some flags or configurations to disable this stuff for a system language. am I right?
>>>>
>>>> I already gave you the solution one message above; betterC (A subset of D) is what you want.
>>>
>>> yes sorry, I saw and I was reading about it, thank you.
>>>
>>> as I found, I can't use some important features in betterC. like classes. but I need them.
>>
>> Are you sure you need classes and can't do with structs?
>
> I need inheritance and other OOP concepts and template features. does D's struct support them? as I found, No.
Structs support templates fully, struct S(T) { ... } is supported.
Inheritance no, but you can sort of cheat with it using alias this.
You can probably achieve what you want without OOP, OOP isn't always the right choice and in most cases people confuse procedural programming with object oriented programming.
|
September 01, 2022 Re: Classes on stack | ||||
---|---|---|---|---|
| ||||
Posted in reply to Redwan | On Thursday, 1 September 2022 at 11:17:20 UTC, Redwan wrote:
> On Thursday, 1 September 2022 at 11:06:31 UTC, bauss wrote:
>> On Thursday, 1 September 2022 at 10:51:44 UTC, Redwan wrote:
>>> [...]
>>
>> I already gave you the solution one message above; betterC (A subset of D) is what you want.
>
> yes sorry, I saw and I was reading about it, thank you.
>
> as I found, I can't use some important features in betterC. like classes. but I need them.
as an alternative to betterC, you could write your own runtime.
|
Copyright © 1999-2021 by the D Language Foundation