Re: basic pointer question
On Friday, 11 July 2025 at 22:17:02 UTC, WhatMeWorry wrote: ``` // working function SDL_Texture* changeTextureAccess(SDL_Texture *texture, SDL_TextureAccess newAccess) { // pertinent code only texture = createTexture(renderer, pixelFormat, newAccess, width, height); return texture; } ``` The above function is working for me when I call it with: ``` SDL_Texture* sameTexture = changeTextureAccess(sameTexture, SDL_TEXTUREACCESS_STREAMING) ``` but I thought a better solution would be simply: ``` void changeTextureAccess(SDL_Texture **texture, SDL_TextureAccess newAccess) ``` Isn't the only way to update a function parameter is by making it a pointer? So I thought something like ``` *texture = createTexture(renderer, pixelFormat, newAccess, width, height); ``` would work but that just leads to a whole bunch of other lines of code returning compiler errors. Am I at least on the right track here? I've been throwing lots of * and & all around and not getting anywhere? You’re going in the right direction yes; SDL_Texture** would be a pointer to a SDL_Texture pointer; however such a pointer needs to be valid. I would recommend using `ref`; eg `ref SDL_Texture*`; which would be safer given that the SDL_Texture* provided then has to be a valid variable to store the pointer into. As for creating and dereferencing references; without seeing the errors in question I am not sure I can provide a good answer.
Re: basic pointer question
On Fri, Jul 11, 2025 at 10:17:02PM +, WhatMeWorry via Digitalmars-d-learn wrote: > ``` > // working function > > SDL_Texture* changeTextureAccess(SDL_Texture *texture, SDL_TextureAccess > newAccess) > { > // pertinent code only > texture = createTexture(renderer, pixelFormat, newAccess, width, > height); > return texture; > } > ``` > > The above function is working for me when I call it with: > ``` > SDL_Texture* sameTexture = changeTextureAccess(sameTexture, > SDL_TEXTUREACCESS_STREAMING) > ``` > but I thought a better solution would be simply: > ``` > void changeTextureAccess(SDL_Texture **texture, SDL_TextureAccess newAccess) > ``` > Isn't the only way to update a function parameter is by making it a pointer? > So I thought something like > ``` > *texture = createTexture(renderer, pixelFormat, newAccess, width, height); > ``` > would work but that just leads to a whole bunch of other lines of code > returning compiler errors. Am I at least on the right track here? I've > been throwing lots of * and & all around and not getting anywhere? [...] What exactly are the errors you're getting? By changing the pointer type, you have to update every place that calls this function so that they pass the address to their pointer rather than the pointer they were originally passing. If you don't want to have to rewrite every caller, and only want to update the pointers inside the function, use `ref`: ``` void changeTextureAccess(ref SDL_Texture *texture, SDL_TextureAccess newAccess) ``` This way, the pointer type doesn't change and the callers don't have to be updated in most cases. They may still need to be updated if they were passing rvalues, since ref cannot bind to rvalues. In that case you'll have to make a copy of the rvalue, or refactor the code to pass an lvalue instead. T -- Heads I win, tails you lose.
basic pointer question
``` // working function SDL_Texture* changeTextureAccess(SDL_Texture *texture, SDL_TextureAccess newAccess) { // pertinent code only texture = createTexture(renderer, pixelFormat, newAccess, width, height); return texture; } ``` The above function is working for me when I call it with: ``` SDL_Texture* sameTexture = changeTextureAccess(sameTexture, SDL_TEXTUREACCESS_STREAMING) ``` but I thought a better solution would be simply: ``` void changeTextureAccess(SDL_Texture **texture, SDL_TextureAccess newAccess) ``` Isn't the only way to update a function parameter is by making it a pointer? So I thought something like ``` *texture = createTexture(renderer, pixelFormat, newAccess, width, height); ``` would work but that just leads to a whole bunch of other lines of code returning compiler errors. Am I at least on the right track here? I've been throwing lots of * and & all around and not getting anywhere?
Re: Is there some kind of Blocking Queue for D?
On Thursday, 10 July 2025 at 23:57:48 UTC, Ali Çehreli wrote: On 7/10/25 7:28 AM, Bienlein wrote: > some blockinglist wrapper around slist I would try std.concurrency first because its message queue is a blocking queue anyway if you limit the size with setMaxMailboxSize(). I have some examples of std.concurrency here: https://ddili.org/ders/d.en/concurrency.html Ali Just saw that inside https://github.com/dlang/phobos/blob/master/std/concurrency.d there is a class MessageBox which does just what I want. Unhappily class MessageBox is private and therefore cannot be reused. I never understood the point of private inner classes as they prevent reuse. If you are forced to design for reuse you are also forced to think about reusable design which makes the design better (and besides allows for reuse).