digitalmars.D.learn - Dup'ing an array onto the stack
- John Demme (8/8) Feb 24 2006 I need to .dup a string on to the stack. I current have:
- Jarrett Billingsley (7/13) Feb 24 2006 I don't think you can have dynamic arrays point to the stack without som...
- John Demme (4/6) Feb 24 2006 It's part of an XML parser for Mango... One of my goals is no memory
- Tom S (12/15) Feb 24 2006 How about:
- John Demme (3/16) Feb 24 2006 That's the code I was looking for. Thanks.
- Jarrett Billingsley (4/7) Feb 25 2006 Huh! Would've thought that that'd've copied the data from the original
I need to .dup a string on to the stack. I current have: char[] str = ...; char[] stackStr = str.dup; But it's a lie, since stackStr is stored on the heap. How do I get it on the stack? I can easily get the space on the stack for it using alloca(), but how do I tell the array to use a certain place in memory? Thanks, John Demme
Feb 24 2006
"John Demme" <me teqdruid.com> wrote in message news:dto0oq$tpg$1 digitaldaemon.com...I need to .dup a string on to the stack. I current have: char[] str = ...; char[] stackStr = str.dup; But it's a lie, since stackStr is stored on the heap. How do I get it on the stack? I can easily get the space on the stack for it using alloca(), but how do I tell the array to use a certain place in memory?I don't think you can have dynamic arrays point to the stack without some ugly hacks. They're not really meant to point at the stack, as that wouldn't work with the dynamic sizing. Only static arrays can be created on the stack. Why do you need it on the stack?
Feb 24 2006
Jarrett Billingsley wrote:Why do you need it on the stack?It's part of an XML parser for Mango... One of my goals is no memory allocations after object construction, and I'm getting pretty close. ~John
Feb 24 2006
John Demme wrote:But it's a lie, since stackStr is stored on the heap. How do I get it on the stack? I can easily get the space on the stack for it using alloca(), but how do I tell the array to use a certain place in memory?How about: char[] foo = (cast(char*)alloca(...))[0 .. bar.length]; foo[] = bar[]; ? -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d-pu s+: a-->----- C+++$>++++ UL P+ L+ E--- W++ N++ o? K? w++ !O !M V? PS- PE- Y PGP t 5 X? R tv-- b DI- D+ G e>+++ h>++ !r !y ------END GEEK CODE BLOCK------ Tomasz Stachowiak /+ a.k.a. h3r3tic +/
Feb 24 2006
That's the code I was looking for. Thanks. ~John Demme Tom S wrote:John Demme wrote:But it's a lie, since stackStr is stored on the heap. How do I get it on the stack? I can easily get the space on the stack for it using alloca(), but how do I tell the array to use a certain place in memory?How about: char[] foo = (cast(char*)alloca(...))[0 .. bar.length]; foo[] = bar[]; ?
Feb 24 2006
"Tom S" <h3r3tic remove.mat.uni.torun.pl> wrote in message news:dto984$1inu$1 digitaldaemon.com...How about: char[] foo = (cast(char*)alloca(...))[0 .. bar.length]; foo[] = bar[];Huh! Would've thought that that'd've copied the data from the original alloca'd buffer, but now that I think about it, I guess it wouldn't.
Feb 25 2006