By default variables are allocated on the stack. This is not the case for "dim shared" (and maybe there are some other exceptions that don't come into my mind currently). When you allocate memory explicitly with new or (c)allocate you get memory from the heap and need to free/delete it yourself. How does this work in PowerBasic? It can't be that different I guess.deltarho[1859] wrote:Dim creates space on the stack? I didn't know that - Help just says "Declares a variable by name and reserves memory to accommodate it." This is also different to PowerBASIC. Ouch!
Hm, would be interesting why it's clearly slower then. On my PC the difference was just marginal, but I've tested a fbc64 debug build on a quite old machine (Q6600, 4-cores) and got 16 or 17 mill/sec there.deltarho[1859] wrote:I am getting '142 mill/sec 145 mill/sec' compared with my 100% code duplication of '195 mill/sec 193 mil/sec'.
Anyway some results seem very strange. For example on my current machine running a fbc32 (-gen gas) build with two threads results in a dramatically lower throughput compared to the single-threaded one. This does not happen for the fbc64 (-gen gcc) build. Maybe there's still some error in the code ..
I think the question is rather: why would we need an empty type? The limitation is probably a technical one. Remember that each function in a type actually has a hidden "this" pointer as argument, but is otherwise identical to "plain" functions (the function exists only once and is technically not part of the type). So e.g.deltarho[1859] wrote:Now, call me old fashioned but we should not have to use a dummy variable to get something to work. For me that is a bug workaround. The compiler should allow an empty type structure and issue a warning along the lines of "Oy, pudding head - you've got an empty ENUM, TYPE or UNION".<smile>
declare function f()
would become something like
declare function f(this as myType ptr)
internally. That would make no sense if myType is empty as there would be a pointer to a zero-length memory. So, what would be the advantage of allowing empty types? You can have the namespace nesting (namespace.function) by using namespaces directly instead of types. Are there any other things?
Of course you're right. I've just been lazy :-) One should generally avoid global variables if not necessary, as you already mentioned.deltarho[1859] wrote:pcg32A did not have to be global [...]
Thanks, but my knowledge about RNG is quite limited.deltarho[1859] wrote:Et tu, Brute?St_W wrote:I think you would be a perfect candidate for improving the RND implementation in FreeBasic's runtime library.