On Wednesday, 2 March 2016 at 10:57:35 UTC, Luis wrote:
Read https://dlang.org/spec/arrays.html#strings and try to use
std.string.toStringz
(http://dlang.org/phobos/std_string.html#.toStringz)
Yes, but that's not what you use when you want to avoid
allocation.
On Wednesday, 2 March 2016 at 04:12:13 UTC, Mike Parker wrote:
On Wednesday, 2 March 2016 at 01:39:13 UTC, David G. Maziero
wrote:
Consider the following function:
void RenderText( FontBMP font, int x, int y, const char* text )
{
for( int r=0; text[r]!='\0'; ++r )
{
You'r
On Wednesday, 2 March 2016 at 05:04:37 UTC, David G. Maziero
wrote:
I figured out what I wanted. Thanks for your answer Mike, sorry
to bother you though.
[...]
Even null-terminated be sure to profile your loop, for isn't
garanteed to be faster than foreach at all and foreach is
definitely s
On Wednesday, 2 March 2016 at 05:04:37 UTC, David G. Maziero
wrote:
void RenderText( FontBMP font, int x, int y, const char* text,
Just one more correction for future reference, RenderText should
be
extern(C) void RenderText...
in order for it to work correctly with va_start/etc.
On Wednesday, 2 March 2016 at 05:04:37 UTC, David G. Maziero
wrote:
char[256] buff;
va_list ap;
va_start( ap, text );
sprintf( buff.ptr, text, ap );
va_end( ap );
Sorry again, where it reads "sprintf" should be "vsprintf".
I figured out what I wanted. Thanks for your answer Mike, sorry
to bother you though.
Here's the result:
void RenderText( FontBMP font, int x, int y, const char* text,
... )
{
SDL_Rect rect1, rect2;
rect2.x = x;
rect2.y = y;
rect2.w = font.width;
rect2.
I forgot to add that the "RenderText(font,0,0,"FPS:
"~to!string(fps));" was an older version where it wasn't const
char *, but string. And I was using a foreach, so no
null-termination. But that's beyond the point of not using GC.
Yes, I'm aware of the null-termination thing. I might have pasted
code that I already changed.
But I already messed with sformat, and it seems that it does use
the GC. I've put @nogc in RenderText, and the compiler says
sformat uses GC, so I don't know.
But the thing is, I don't want to buil
On Wednesday, 2 March 2016 at 04:12:13 UTC, Mike Parker wrote:
char buf[1024];
Ugh. And the proper declaration in D:
char[1024] buf;
On Wednesday, 2 March 2016 at 01:39:13 UTC, David G. Maziero
wrote:
Consider the following function:
void RenderText( FontBMP font, int x, int y, const char* text )
{
for( int r=0; text[r]!='\0'; ++r )
{
You're asking for trouble here. There's no guarantee that any D
stri
Hi. I think it's the first time I post here.
I've been flirting with D for some time, but now I decided to
start a little project.
Consider the following function:
void RenderText( FontBMP font, int x, int y, const char* text )
{
SDL_Rect rect1, rect2;
rect2.x = x;
rect
11 matches
Mail list logo