Re: convert ubyte[k..k + 1] to int

2012-05-16 Thread Andrew Wiley
On Wed, May 16, 2012 at 11:07 PM, H. S. Teoh wrote: > On Wed, May 16, 2012 at 10:25:51PM -0500, Andrew Wiley wrote: > > On Wed, May 16, 2012 at 11:03 AM, Regan Heath > wrote: > > > > > On Wed, 16 May 2012 15:24:33 +0100, ref2401 > wrote: > > > > > > i have an array of ubytes. how can i convert

Re: convert ubyte[k..k + 1] to int

2012-05-16 Thread H. S. Teoh
On Wed, May 16, 2012 at 10:25:51PM -0500, Andrew Wiley wrote: > On Wed, May 16, 2012 at 11:03 AM, Regan Heath wrote: > > > On Wed, 16 May 2012 15:24:33 +0100, ref2401 wrote: > > > > i have an array of ubytes. how can i convert two adjacent ubytes from the > >> array to an integer? > >> > >> pse

Re: std.file, std.stdio(File), std.stream(File:Stream)

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 20:58:02 H. S. Teoh wrote: > Hindsight is always 20/20. I agree with you that it makes sense... but > only after you've learned what it is. This does not help newcomers nor > give them a good impression of D. We need to reduce the amount of stuff > that only makes sense

Re: std.file, std.stdio(File), std.stream(File:Stream)

2012-05-16 Thread H. S. Teoh
On Wed, May 16, 2012 at 08:37:08PM -0700, Jonathan M Davis wrote: > On Tuesday, May 15, 2012 09:48:23 H. S. Teoh wrote: > > On Tue, May 15, 2012 at 07:47:24PM +0400, Dmitry Olshansky wrote: > > > On 15.05.2012 19:32, H. S. Teoh wrote: > > > >On Tue, May 15, 2012 at 05:14:15PM +0200, ref2401 wrote:

Re: std.file, std.stdio(File), std.stream(File:Stream)

2012-05-16 Thread Jonathan M Davis
On Tuesday, May 15, 2012 09:48:23 H. S. Teoh wrote: > On Tue, May 15, 2012 at 07:47:24PM +0400, Dmitry Olshansky wrote: > > On 15.05.2012 19:32, H. S. Teoh wrote: > > >On Tue, May 15, 2012 at 05:14:15PM +0200, ref2401 wrote: > > >>general question: > > >>-std.file, > > > > > >std.file is badly name

Re: convert ubyte[k..k + 1] to int

2012-05-16 Thread Andrew Wiley
On Wed, May 16, 2012 at 11:03 AM, Regan Heath wrote: > On Wed, 16 May 2012 15:24:33 +0100, ref2401 wrote: > > i have an array of ubytes. how can i convert two adjacent ubytes from the >> array to an integer? >> >> pseudocode example: >> ubyte[5] array = createArray(); >> int value = array[2..3]

Re: convert ubyte[k..k + 1] to int

2012-05-16 Thread Jonathan M Davis
On Thursday, May 17, 2012 02:32:55 Robert DaSilva wrote: > On Wednesday, 16 May 2012 at 18:47:55 UTC, Jonathan M Davis wrote: > > As long as you're going from big endian to little endian, > > std.bitmanip.bigEndianToNative will do the conversion fairly > > easily, but if > > they're in little endia

Re: convert ubyte[k..k + 1] to int

2012-05-16 Thread Robert DaSilva
On Wednesday, 16 May 2012 at 18:47:55 UTC, Jonathan M Davis wrote: As long as you're going from big endian to little endian, std.bitmanip.bigEndianToNative will do the conversion fairly easily, but if they're in little endian, then the nasty casting is the way to go. - Jonathan M Davis Exce

Re: DMD Bug or not? foreach over struct range

2012-05-16 Thread Era Scarecrow
On Wednesday, 16 May 2012 at 20:50:55 UTC, Nick Sabalausky wrote: I was initially open to the idea I may have just misunderstood something, but I'm becoming more and more convinced that the current "foreach over an implicit copy" behavior is indeed a bad idea. I'd love to see Andrei weigh in

Re: DMD Bug or not? foreach over struct range

2012-05-16 Thread Nick Sabalausky
Actually, I think I'm going to move this over to "digitalmars.D". Seems a more appropriate place at this point.

Re: allocate array with new

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 12:05:02 H. S. Teoh wrote: > It would be nice if there was an easy way of switching allocators, so > that you can, for example, indicate that all allocations done inside a > particular function should use malloc/free (including, say, AA's, > arrays, etc.), and have the ru

Re: DMD Bug or not? foreach over struct range

2012-05-16 Thread Nick Sabalausky
"Jonathan M Davis" wrote in message news:mailman.828.1337154007.24740.digitalmars-d-le...@puremagic.com... > On Wednesday, May 16, 2012 03:29:23 Nick Sabalausky wrote: >> "Jonathan M Davis" wrote in message >> news:mailman.826.1337151940.24740.digitalmars-d-le...@puremagic.com... >> >> > No. Tha

Re: ProjectEuler problem 35

2012-05-16 Thread Andrea Fontana
Original code in this thread run on my pc in ~400ms. With my skipping method it takes just ~10ms. But I think there're more improvement. However using CTFE I guess time goes down to 0 ;) On Wednesday, 16 May 2012 at 19:50:45 UTC, Era Scarecrow wrote: On Wednesday, 16 May 2012 at 13:10:06 UTC,

Re: ProjectEuler problem 35

2012-05-16 Thread Era Scarecrow
On Wednesday, 16 May 2012 at 13:10:06 UTC, Tiberiu Gal wrote: The correct answer is 55 Your versions of isCircularPrime just truncates the number ( this is actually useful in a next problem though; ) Hmm glancing at the original source I see what you mean. A slight modification to fill prim

Re: ProjectEuler problem 35

2012-05-16 Thread Ali Çehreli
On 05/16/2012 07:14 AM, Tiberiu Gal wrote: > "You'll skip 70% of checks..." > that's true for the Circular check ... but in the whole app, the most > time is spent finding primes. A number that cannot be circular prime need not be checked whether regular prime. Ali -- D Programming Language T

Re: allocate array with new

2012-05-16 Thread H. S. Teoh
On Wed, May 16, 2012 at 02:20:47PM -0400, Jonathan M Davis wrote: > On Wednesday, May 16, 2012 13:52:12 Steven Schveighoffer wrote: > > Where the GC gets into trouble is with allocation of large chunks of > > data. > > > > If the data 'contains pointers', it creates a very good chance that > > the

Re: convert ubyte[k..k + 1] to int

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 17:03:44 Regan Heath wrote: > On Wed, 16 May 2012 15:24:33 +0100, ref2401 wrote: > > i have an array of ubytes. how can i convert two adjacent ubytes from > > the array to an integer? > > > > pseudocode example: > > ubyte[5] array = createArray(); > > int value = array[

Re: allocate array with new

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 13:52:12 Steven Schveighoffer wrote: > Where the GC gets into trouble is with allocation of large chunks of data. > > If the data 'contains pointers', it creates a very good chance that the > data keeps some unknown number of blocks from being deallocated. > > And just

Re: Translating C const

2012-05-16 Thread Simon
On 16/05/2012 09:24, Jacob Carlborg wrote: On 2012-05-16 09:00, Jonathan M Davis wrote: Probably true. But also, if you're talking about a const pointer to a mutable value, the constness of the pointer is actually irrelevant to the caller. The pointer will be copied when the function is called,

Re: allocate array with new

2012-05-16 Thread Steven Schveighoffer
On Wed, 16 May 2012 12:52:33 -0400, Jonathan M Davis wrote: On Wednesday, May 16, 2012 11:51:59 Steven Schveighoffer wrote: Well, the D GC is conservative, and will always be at least partly conservative. So freeing memory manually is not really a crime. The idea with a GC is that it's sup

Re: allocate array with new

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 11:51:59 Steven Schveighoffer wrote: > Well, the D GC is conservative, and will always be at least partly > conservative. So freeing memory manually is not really a crime. The idea with a GC is that it's supposed to manage the memory allocated through it. So, if you're

Re: convert ubyte[k..k + 1] to int

2012-05-16 Thread Regan Heath
On Wed, 16 May 2012 15:24:33 +0100, ref2401 wrote: i have an array of ubytes. how can i convert two adjacent ubytes from the array to an integer? pseudocode example: ubyte[5] array = createArray(); int value = array[2..3]; is there any 'memcpy' method or something else to do this? You don

Re: D Dll injection problem

2012-05-16 Thread Kagamin
Hmm... It's probably confused by multiple threads. You can try to copy the source for dll_process_attach and insert debugging code there.

Re: allocate array with new

2012-05-16 Thread Steven Schveighoffer
On Tue, 15 May 2012 05:43:45 -0400, Jonathan M Davis wrote: On Tuesday, May 15, 2012 11:26:49 Namespace wrote: On Tuesday, 15 May 2012 at 09:23:51 UTC, Kagamin wrote: > Difference with what? > new is a safe feature: it allocates in the GC heap That's what i mean. So i have to delete it your

Re: void pointer syntax

2012-05-16 Thread Chris Cain
On Wednesday, 16 May 2012 at 11:12:19 UTC, Stephen Jones wrote: Cain: My understanding is that D is based on "no proper ways of doing things" just get the job done. The use of properties when you can use public access baffles me. So long as you are I suppose "proper way of doing things" isn't

Re: ProjectEuler problem 35

2012-05-16 Thread Tiberiu Gal
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. How many circular primes are there below one million? =

convert ubyte[k..k + 1] to int

2012-05-16 Thread ref2401
i have an array of ubytes. how can i convert two adjacent ubytes from the array to an integer? pseudocode example: ubyte[5] array = createArray(); int value = array[2..3]; is there any 'memcpy' method or something else to do this?

Re: ProjectEuler problem 35

2012-05-16 Thread Tiberiu Gal
"You'll skip 70% of checks..." that's true for the Circular check ... but in the whole app, the most time is spent finding primes. On Wednesday, 16 May 2012 at 14:01:19 UTC, Andrea Fontana wrote: Not that big gain? If you check for circulars numbers from 0 to 1.000.000 you can skip interval

Re: ProjectEuler problem 35

2012-05-16 Thread Andrea Fontana
Probabily i miss the point. Are you looking for prime & circular primes or for circular primes only? On Wednesday, 16 May 2012 at 14:14:15 UTC, Tiberiu Gal wrote: "You'll skip 70% of checks..." that's true for the Circular check ... but in the whole app, the most time is spent finding primes.

Re: ProjectEuler problem 35

2012-05-16 Thread Tiberiu Gal
On Wednesday, 16 May 2012 at 09:46:06 UTC, Dmitry Olshansky wrote: On 16.05.2012 13:26, Tiberiu Gal wrote: hi many claim their code solves the problem in order of ms ( c/pascal/haskell code) my D code takes ~1.5 seconds. Can it be made faster ( without pointers )? it runs the same with or with

Re: ProjectEuler problem 35

2012-05-16 Thread Andrea Fontana
Not that big gain? If you check for circulars numbers from 0 to 1.000.000 you can skip intervals from 200.000 to 299.999, from 400.000 to 699.999 and from 800.000 to 899.999 (and other sub-intervals, of course). You'll skip 70% of checks... On Wednesday, 16 May 2012 at 13:14:37 UTC, Tiberiu

Re: ProjectEuler problem 35

2012-05-16 Thread Tiberiu Gal
Good point there, unfortunately it's not that big a gain in this particular instance. thank you On Wednesday, 16 May 2012 at 12:46:07 UTC, Andrea Fontana wrote: What about some logic optimizations? F.E. if number contains one of these digit 0,2,4,6,8,5 is not circular of course .. On Wedn

Re: ProjectEuler problem 35

2012-05-16 Thread Tiberiu Gal
The correct answer is 55 Your versions of isCircularPrime just truncates the number ( this is actually useful in a next problem though; ) prime_walks is a nice and efficient way to find primes ... and not a bit n00bfriendly. I'm not posting it anywhere, I'm just learning and having fun. On

Re: ProjectEuler problem 35

2012-05-16 Thread Andrea Fontana
What about some logic optimizations? F.E. if number contains one of these digit 0,2,4,6,8,5 is not circular of course .. On Wednesday, 16 May 2012 at 09:26:45 UTC, Tiberiu Gal wrote: hi many claim their code solves the problem in order of ms ( c/pascal/haskell code) my D code takes ~1.5

Re: void pointer syntax

2012-05-16 Thread dennis luehring
>Am 16.05.2012 13:12, schrieb Stephen Jones: just throw aways your sensless void pointer or whatever idea - create a base interface or better base-class - everything else is just damn wrong btw: all oop widget sets for c++, java or else are haveing a widget base class that works like people t

Re: void pointer syntax

2012-05-16 Thread Era Scarecrow
On Wednesday, 16 May 2012 at 11:12:19 UTC, Stephen Jones wrote: Ali your post above, and T your post in the other forum (Simpsons bit) is sort of what I was after. I tried both interface and abstract class but not outright super class. The problem I have with the solution is the same problem I

Re: void pointer syntax

2012-05-16 Thread Stephen Jones
On Wednesday, 16 May 2012 at 02:55:41 UTC, H. S. Teoh wrote: On Wed, May 16, 2012 at 04:01:23AM +0200, Stephen Jones wrote: [...] Using Object gives exactly the same problem as the Object super class does not have vcount variable. Casting is not a solution because the reason for throwing differe

Re: ProjectEuler problem 35

2012-05-16 Thread Era Scarecrow
On Wednesday, 16 May 2012 at 09:46:06 UTC, Dmitry Olshansky wrote: On 16.05.2012 13:26, Tiberiu Gal wrote: foreach(i; 2 .. Max) { //writefln("is %s prime ? %s ", i, i.isPrime); if( i.isPrime && i.isCircularPrime) { cnt++; Curiously i've just posted a sample (as part of another topic) that

Re: ProjectEuler problem 35

2012-05-16 Thread Dmitry Olshansky
On 16.05.2012 13:26, Tiberiu Gal wrote: hi many claim their code solves the problem in order of ms ( c/pascal/haskell code) my D code takes ~1.5 seconds. Can it be made faster ( without pointers )? it runs the same with or without caching the primes, and most of the time it spends finding prime

ProjectEuler problem 35

2012-05-16 Thread Tiberiu Gal
hi many claim their code solves the problem in order of ms ( c/pascal/haskell code) my D code takes ~1.5 seconds. Can it be made faster ( without pointers )? it runs the same with or without caching the primes, and most of the time it spends finding primes; isCircularPrime can be optimized

Re: Translating C const

2012-05-16 Thread Jacob Carlborg
On 2012-05-16 09:00, Jonathan M Davis wrote: Probably true. But also, if you're talking about a const pointer to a mutable value, the constness of the pointer is actually irrelevant to the caller. The pointer will be copied when the function is called, so it doesn't matter on whit whether the po

Re: DMD Bug or not? foreach over struct range

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 09:48:20 Era Scarecrow wrote: > Hmmm... > [quote] > void main() > { > Foo foo; > foreach(val; foo) > writeln(foo.val, " ", val); > } > [/quote] > > Indeed... he is using foo.val isn't he? Instead he should just > use 'val' by itself. Well, there's n

Re: Problem using Interfce

2012-05-16 Thread Ary Manzana
On 5/16/12 9:24 AM, Stephen Jones wrote: Ary: I seem to remember playing around with a Simpsons extending program in Java that did this; you could throw all the different Simpsons into a single Array because they extended "Simpson", and you could walk through the array and each would call their o

Re: DMD Bug or not? foreach over struct range

2012-05-16 Thread Era Scarecrow
On Wednesday, 16 May 2012 at 07:41:14 UTC, Jonathan M Davis wrote: void main() { prime_walk pw; pw.cap = 100; foreach(i; pw) writefln("%s %s", i, pw.position); } You'd see that pw.postion is always printed as 2, just like Nick's foo.val always prints as 0. Hmmm... [quote

Re: DMD Bug or not? foreach over struct range

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 09:24:23 Era Scarecrow wrote: > On Wednesday, 16 May 2012 at 07:04:09 UTC, Jonathan M Davis wrote: > > that assertion would pass, but it doesn't, and it shouldn't. If > > your range was a reference type (e.g. if it were a class or it > > was like the ranges in std.stdio w

Re: DMD Bug or not? foreach over struct range

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 03:29:23 Nick Sabalausky wrote: > "Jonathan M Davis" wrote in message > news:mailman.826.1337151940.24740.digitalmars-d-le...@puremagic.com... > > > No. That's expected. Your range is a value type, so it got copied when you > > used it with foreach. > > But foreach isn

Re: DMD Bug or not? foreach over struct range

2012-05-16 Thread Nick Sabalausky
"Jonathan M Davis" wrote in message news:mailman.826.1337151940.24740.digitalmars-d-le...@puremagic.com... > > No. That's expected. Your range is a value type, so it got copied when you > used it with foreach. But foreach isn't a function, it's a flow-control statement.

Re: DMD Bug or not? foreach over struct range

2012-05-16 Thread Era Scarecrow
On Wednesday, 16 May 2012 at 07:04:09 UTC, Jonathan M Davis wrote: that assertion would pass, but it doesn't, and it shouldn't. If your range was a reference type (e.g. if it were a class or it was like the ranges in std.stdio which deal with I/O), then using it with foreach would consume it, b

Re: What is a good strategy for finding undefined symbols...

2012-05-16 Thread Mike Parker
On 5/16/2012 10:15 AM, WhatMeWorry wrote: I'm just going start from scratch. However, this might be a real beginner question, but when I go to the ttp://svn.dsource.org/projects/derelict/branches/Derelict2 link, I see Revision 630: /branches/Derelict2 .. DerelictAL/ DerelictAllegro/ DerelictFM

Re: DMD Bug or not? foreach over struct range

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 09:15:06 bearophile wrote: > Nick Sabalausky: > > It seems that foreach is iterating over an implicit copy of > > 'foo' instead of > > 'foo' itself. Is this correct behavior, or a DMD bug? > > This program prints "[11, 21, 31]" so for fixed-size arrays (that > are values

Re: DMD Bug or not? foreach over struct range

2012-05-16 Thread bearophile
Nick Sabalausky: It seems that foreach is iterating over an implicit copy of 'foo' instead of 'foo' itself. Is this correct behavior, or a DMD bug? This program prints "[11, 21, 31]" so for fixed-size arrays (that are values as much as structs) it doesn't perform a copy: import std.stdio; v

Re: DMD Bug or not? foreach over struct range

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 02:43:19 Nick Sabalausky wrote: > This code: > > -- > import std.stdio; > > struct Foo > { > int val; > > @property bool empty() { > return val >= 5; > } > > @property int front() { > return val;

Re: Translating C const

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 08:50:27 Jacob Carlborg wrote: > On 2012-05-16 07:35, Simen Kjaeraas wrote: > > That depends. Will the contents be modified? > > I have no idea. I'm working on a tool for automatically translating C > headers. I was thinking since I don't know, I better not add any > pro