Does D have some way to dynamically allocate on the stack? I'm
looking for something roughly equivalent to the following C code.
int doSomething(size_t len)
{
char stackBuffer[len + 1];
doSomethingElse(stackBuffer);
}
Thanks,
Mike
On Saturday, 21 April 2018 at 07:37:50 UTC, Mike Franklin wrote:
Does D have some way to dynamically allocate on the stack? I'm
looking for something roughly equivalent to the following C
code.
int doSomething(size_t len)
{
char stackBuffer[len + 1];
doSomethingElse(stackBuffer);
}
On 21.04.2018 12:08, Giles Bathgate wrote:
On Saturday, 21 April 2018 at 07:57:41 UTC, Uknown wrote:
The language itself doesn't have something, but you could use `alloca`
I don't know if this little template function makes life easier:
--
pragma(inline, true)
ref T push(T)(size_t len)
{
On Saturday, 21 April 2018 at 13:54:14 UTC, H. S. Teoh wrote:
On Sat, Apr 21, 2018 at 01:30:55PM +, Cym13 via
Digitalmars-d-learn wrote:
On Saturday, 21 April 2018 at 12:08:09 UTC, Dmitry Olshansky
wrote:
[...]
> Unbounded allocation on stack is kind of anti-pattern and a
> potential DoS
On Thursday, 19 April 2018 at 17:55:47 UTC, Simen Kjærås wrote:
Your first example defines two templates (which are overloads
of the same name), the second only one. There's no ambiguity
there.
So, do you mean, that the constraint belongs to the interface of
a template?
On Saturday, 21 April 2018 at 07:37:50 UTC, Mike Franklin wrote:
Does D have some way to dynamically allocate on the stack? I'm
looking for something roughly equivalent to the following C
code.
int doSomething(size_t len)
{
char stackBuffer[len + 1];
doSomethingElse(stackBuffer);
}
On Saturday, 21 April 2018 at 12:08:09 UTC, Dmitry Olshansky
wrote:
On Saturday, 21 April 2018 at 07:37:50 UTC, Mike Franklin wrote:
Does D have some way to dynamically allocate on the stack?
I'm looking for something roughly equivalent to the following
C code.
int doSomething(size_t len)
{
import std.meta : Filter;
enum isNotReservedSymbol(string name) = name != "none" && name !=
"lastToken";
enum string[] members = staticMembers!Token;
static foreach(member; Filter!(isNotReservedSymbol, members))
{{
This return the error:
Error: template instance
On Saturday, 21 April 2018 at 07:57:41 UTC, Uknown wrote:
The language itself doesn't have something, but you could use
`alloca`
I don't know if this little template function makes life easier:
--
pragma(inline, true)
ref T push(T)(size_t len)
{
import core.stdc.stdlib,
On Saturday, 21 April 2018 at 10:08:43 UTC, Giles Bathgate wrote:
I don't know if this little template function makes life easier:
Sorry, that doesn't work at all.
On Saturday, 21 April 2018 at 10:47:47 UTC, Timon Gehr wrote:
That does not work (you are returning a dangling reference into
the stack of the function that is returning).
Yeah I had hoped that the pragma(inline, true) would solve that,
but it dosesn't :(
On Sat, Apr 21, 2018 at 01:30:55PM +, Cym13 via Digitalmars-d-learn wrote:
> On Saturday, 21 April 2018 at 12:08:09 UTC, Dmitry Olshansky wrote:
[...]
> > Unbounded allocation on stack is kind of anti-pattern and a
> > potential DoS vector.
>
> I'm having trouble seeing how unbounded heap
On Saturday, 21 April 2018 at 07:57:41 UTC, Uknown wrote:
The language itself doesn't have something.
It would be cool if you could just do
int doSomething(size_t len)
{
char stackBuffer = push char[len + 1];
doSomethingElse(stackBuffer);
}
i.e some kind of `push`
On Saturday, 21 April 2018 at 07:37:50 UTC, Mike Franklin wrote:
Does D have some way to dynamically allocate on the stack? I'm
looking for something roughly equivalent to the following C
code.
int doSomething(size_t len)
{
char stackBuffer[len + 1];
doSomethingElse(stackBuffer);
}
On Saturday, 21 April 2018 at 13:30:55 UTC, Cym13 wrote:
[...]
Nevermind, forgot that shared libraries are put between the two.
On Saturday, 21 April 2018 at 19:06:52 UTC, Steven Schveighoffer
wrote:
alloca is an intrinsic, and part of the language technically --
it has to be.
From what I can tell `alloca` is only available in the platform's
C standard library (actually for Linux it appears be part of
libgcc as
On Sunday, 22 April 2018 at 01:07:44 UTC, Giles Bathgate wrote:
On Saturday, 21 April 2018 at 19:06:52 UTC, Steven
Schveighoffer wrote:
alloca is an intrinsic, and part of the language technically
-- it has to be.
Why does:
scope c = new C(); // allocate c on stack
scope a = new
On 4/21/18 1:46 PM, Dr.No wrote:
On Saturday, 21 April 2018 at 17:15:47 UTC, Jonathan M Davis wrote:
On Saturday, April 21, 2018 16:05:22 Dr.No via Digitalmars-d-learn wrote:
import std.meta : Filter;
enum isNotReservedSymbol(string name) = name != "none" && name !=
"lastToken";
enum string[]
On Saturday, 21 April 2018 at 23:47:41 UTC, Mike Franklin wrote:
On Saturday, 21 April 2018 at 19:06:52 UTC, Steven
Schveighoffer wrote:
alloca is an intrinsic, and part of the language technically
-- it has to be.
From what I can tell `alloca` is only available in the
platform's C
On Sunday, 22 April 2018 at 01:26:09 UTC, Uknown wrote:
Its a special case for classes. Makes them usable without the
GC.
The intention was actually just to have deterministic destruction
- a scope class ctor runs at the end of scope (and it used to be
you could force a class to always be
On Saturday, 21 April 2018 at 17:46:05 UTC, Dr.No wrote:
On Saturday, 21 April 2018 at 17:15:47 UTC, Jonathan M Davis
wrote:
On Saturday, April 21, 2018 16:05:22 Dr.No via
Digitalmars-d-learn wrote:
import std.meta : Filter;
enum isNotReservedSymbol(string name) = name != "none" &&
name !=
On Saturday, 21 April 2018 at 19:06:52 UTC, Steven Schveighoffer
wrote:
alloca is an intrinsic, and part of the language technically --
it has to be.
Why does:
scope c = new C(); // allocate c on stack
scope a = new char[len]; // allocate a via gc?
what flags to use so that the intermediate .o files are discared
by ldc and only a.out is written to disk
On 4/21/18 7:47 PM, Mike Franklin wrote:
On Saturday, 21 April 2018 at 19:06:52 UTC, Steven Schveighoffer wrote:
alloca is an intrinsic, and part of the language technically -- it has
to be.
From what I can tell `alloca` is only available in the platform's C
standard library (actually for
On Sunday, April 22, 2018 01:07:44 Giles Bathgate via Digitalmars-d-learn
wrote:
> On Saturday, 21 April 2018 at 19:06:52 UTC, Steven Schveighoffer
>
> wrote:
> > alloca is an intrinsic, and part of the language technically --
> > it has to be.
>
> Why does:
>
> scope c = new C(); //
On Sunday, 22 April 2018 at 00:41:34 UTC, Nicholas Wilson wrote:
You're not using the C library version of it, the compiler does
the stack space reservation inline for you. There is no way
around this.
I'm not convinced. I did some no-runtime testing and eventually
found the implementation
On Saturday, April 21, 2018 16:05:22 Dr.No via Digitalmars-d-learn wrote:
> import std.meta : Filter;
> enum isNotReservedSymbol(string name) = name != "none" && name !=
> "lastToken";
> enum string[] members = staticMembers!Token;
> static foreach(member; Filter!(isNotReservedSymbol, members))
>
On Saturday, 21 April 2018 at 13:30:55 UTC, Cym13 wrote:
On Saturday, 21 April 2018 at 12:08:09 UTC, Dmitry Olshansky
wrote:
On Saturday, 21 April 2018 at 07:37:50 UTC, Mike Franklin
wrote:
Does D have some way to dynamically allocate on the stack?
I'm looking for something roughly equivalent
On Saturday, April 21, 2018 17:46:05 Dr.No via Digitalmars-d-learn wrote:
> On Saturday, 21 April 2018 at 17:15:47 UTC, Jonathan M Davis
>
> wrote:
> > On Saturday, April 21, 2018 16:05:22 Dr.No via
> >
> > Digitalmars-d-learn wrote:
> >> import std.meta : Filter;
> >> enum
Hi All,
The function rmdirRecurse does not work in Windows if the file
has the READ ONLY permission, so to over come this issue, i have
written the below function to set the permission on file and
folder using the function "setAttributes" , so can any one advice
me whether the below code
On Saturday, 21 April 2018 at 11:23:33 UTC, Alex wrote:
On Thursday, 19 April 2018 at 17:55:47 UTC, Simen Kjærås wrote:
Your first example defines two templates (which are overloads
of the same name), the second only one. There's no ambiguity
there.
So, do you mean, that the constraint
On Saturday, 21 April 2018 at 19:51:05 UTC, Simen Kjærås wrote:
On Saturday, 21 April 2018 at 11:23:33 UTC, Alex wrote:
So, do you mean, that the constraint belongs to the interface
of a template?
Not necessarily - it depends on what you want to achieve. The
only thing I mean is that the
On Saturday, 21 April 2018 at 17:15:47 UTC, Jonathan M Davis
wrote:
On Saturday, April 21, 2018 16:05:22 Dr.No via
Digitalmars-d-learn wrote:
import std.meta : Filter;
enum isNotReservedSymbol(string name) = name != "none" && name
!=
"lastToken";
enum string[] members = staticMembers!Token;
On 4/21/18 3:57 AM, Uknown wrote:
On Saturday, 21 April 2018 at 07:37:50 UTC, Mike Franklin wrote:
Does D have some way to dynamically allocate on the stack? I'm
looking for something roughly equivalent to the following C code.
int doSomething(size_t len)
{
char stackBuffer[len + 1];
On Saturday, 21 April 2018 at 14:25:58 UTC, Cym13 wrote:
On Saturday, 21 April 2018 at 13:54:14 UTC, H. S. Teoh wrote:
On Sat, Apr 21, 2018 at 01:30:55PM +, Cym13 via
Digitalmars-d-learn wrote:
On Saturday, 21 April 2018 at 12:08:09 UTC, Dmitry Olshansky
wrote:
[...]
> Unbounded
35 matches
Mail list logo