Jump to content

  • Log In with Google      Sign In   
  • Create Account


Jan Wassenberg

Member Since 16 Sep 2002
Offline Last Active Jul 22 2014 08:18 PM
-----

#5154221 Wonderfully simple OpenGL UI

Posted by Jan Wassenberg on 17 May 2014 - 01:57 AM

Here's a brief writeup of a simple (9 KLOC, 340 KB binary) but capable and portable OpenGL GUI:

http://wassenberg.dreamhosters.com/blog/2014-05-17/wonderfully-simple-gui/

 

Obligatory screenshot: ui.png

 

Header files are attached: Attached File  ui_headers.zip   5.62KB   30 downloads

 

I'd love to get a discussion going on any perceived shortcomings of this approach, missing features,

alternative libraries that didn't show up in my search, and your thoughts in general.




#4782599 New Tech for the win!

Posted by Jan Wassenberg on 06 March 2011 - 05:34 PM

any day now corn could mutate into flesh eating plants. We should stop growing corn for this reason.

Thank you for that valuable contribution, which is the last of its ilk I will comment upon.




#4782409 New Tech for the win!

Posted by Jan Wassenberg on 06 March 2011 - 08:09 AM

Well you know that we already grow genetically alltered plants all over the world producing our food?

You say that as if it might be surprising (large majorities of consumers in Europe are aware of and opposed to GM food, at least until the consequences are better understood) or a good thing.
Let's see what the National Research Council's "Committee on Identifying and Assessing Unintended Effects of Genetically Engineered Foods on Human Health" (http://www.nap.edu/c...record_id=10977) has to say about this:

All evidence evaluated to date indicates that unexpected and unintended compositional changes arise with all forms of genetic modification, including genetic engineering.

There is a need, in the committee’s judgment, for a broad research and technology development agenda to improve methods for predicting, identifying, and assessing unintended health effects from the genetic modification of food.

So which unintended and unforeseen consequences have arisen in the intervening years?
http://www.globalres...xt=va&aid=12432
Oops, looks like it can negatively impact soil microbes and quality.

Another retrospective from the Board on Agriculture and Natural Resources (http://www.nap.edu/c...record_id=12804) says:

The first generation of genetically engineered (GE) crops has mostly delivered effective pest control for a few major crops because farmers producing these crops spend a lot of time and money on the task, because the firms developing the new seed technologies saw considerable profit potential in doing so, and because adding the traits was relatively straightforward [..]. The first generation of GE crops continues a reliance on pesticide technology—in-plant toxins or resistance to herbicides—to mitigate pest problems primarily in corn, cotton, and soybean. Thus, the application of genetic-engineering technology to crops has not developed novel means of pest control, such as developing plant mechanisms to resist pest damage

So our savior that will supposedly secure the future of agriculture and feed mankind is a new pesticide ("Roundup" := glyphosate) that can be used because plants have been engineered to resist its effects.

However, glyphosate is often applied in higher doses and with greater frequency than the herbicides it replaced. [..]
Ten species have evolved resistance to glyphosate independently in glyphosate-resistant crops over 14 years in the United States (from 1996 to 2010) (Heap, 2010). [..] the nearly exclusive reliance on glyphosate for weed control, a practice accelerated by the widespread introduction of glyphosate-resistant crop varieties, has caused substantial changes in weed communities.

What a big surprise, the quick and easy chemical solution works for a short time and then loses its effectiveness. When will people learn that there is no silver bullet?!

Among the known social facts associated with the dissemination of GE crops are the continued consolidation of the seed industry and its integration with the chemical industry. Another is the change in relationships between farmers and their seed suppliers. Testimony to the committee suggested that farmers of major crops have fewer opportunities to purchase non-GE seed of the best-yielding cultivars even when a GE trait is not perceived to be required in a particular cropping situation.

And there we have one of the apparent driving forces behind GM - corporate greed.
I would be a lot more confident in the technology if it were at least extensively tested before commercialization, which probably necessitates the public sector. Fortunately, China is starting to invest heavily there, so maybe we will see improvements actually aimed at feeding people instead of profits.

I really think people have to step away from the view keep everything as it is.

Straw man argument.

But here the ethanol is produced directly inside the plant during photosynthesis so its actually a clean product and they can make just like the real stuff.

The problems listed in my previous post apply to pure ethanol, regardless of its source.
I'm not sure whether this bioethanol counts as such, since the article mentions problems separating it from water.

The organism they created can create ethanol OR diesel fuel. It is not just ethanol. That's part of the reason it's such a significant discovery.

Yep, I saw that in the article, but it also mentions "Jaguars and jet engines". Granted, there are apparently Diesel-fueled Jaguars, but jet engine is still a stretch despite the existence of multi-fuel tank turbines.


#4782057 New Tech for the win!

Posted by Jan Wassenberg on 05 March 2011 - 08:29 AM

Using genetically modified bacteria to produce specific molecules is a completely normal part of modern pharmaceutical production.

Sure, but that's in a factory, whereas I assume wide-scale production of this stuff would occur in much less controlled environments.

There are also several problems with bioethanol as fuel for (older) gasoline motors:
1) about 10% of current models can sustain serious damage after a single tankful (corroding aluminum, dissolving gaskets)
2) it only has 2/3 the energy density of gasoline => 1..1.9% less mileage, worse acceleration, higher engine RPMs and increased wear
3) There don't seem to be any long-term studies of the effects on current cars - they're less vulnerable to the corrosion and gasket issues, but who knows what else. The differences in additives and volatilization might also be relevant, but I'm definitely out of my depth here. Anyway, it seems foolish to lean on the bioethanol crutch (with unknown side effects) rather than focusing on true alternatives to fossil fuels.

Sources:
http://www.focus.de/...aid_601141.html
http://www.oldtimer-...x.php?Seite=111


#4780633 What are unions good for?

Posted by Jan Wassenberg on 01 March 2011 - 01:18 PM

I understand that you can cast a type to char*, but it's not compliant to cast char* back into another type.

And what is this understanding based on?
You can cast until the cows come home. What is important is that all accesses to a stored value occur through the same pointer (or "by an lvalue expression that has .. character type" [ANSI C99 6.5#7]).

(This is part of a neat little hack used in some 3D engines to approximate the square root operation)

Which used to be a good idea 10..15 years ago, but I'd expect it to be slower now than the SQRTSS instruction generated by a simple call to fsqrtf().

I'd have to do something like this right?

Ooh. Numerous problems with that code:
- unnecessary reinterpret_cast
- incorrect end pointer in the second std::copy
- using std::copy, which must be able to handle overlapping ranges, instead of memcpy
- right-shifts on negative integers are undefined

Clearly this is impractical if the reason for using type punning is performance.

That is anything but clear. Can you justify that statement?
After fixing the above, I see the following code generated (ICC 12.1):
000000013F7B1058 mov edx,dword ptr [dest]
000000013F7B105B shr edx,1
000000013F7B105D mov dword ptr [dest],edx

Speaking of strict aliasing, how does one use the malloc function when it returns a void pointer? Isn't casting this pointer to another type considered a violation?

Nope. Please see ANSI C99 6.7.3#15.


#4779648 What are unions good for?

Posted by Jan Wassenberg on 27 February 2011 - 07:50 AM

Please don't write, much less advocate, such non-standard-conforming code.
Both C99 and C++03 say only one union member can be active at a time and provide an explicit exception for accessing a common sequence (usually a type tag) in Bearhugger's union-of-structs. This exception would not be necessary if it were generally legal to access a different field than was last written.

It's important to stamp out such sloppy and senseless non-conforming code because it interferes with aliasing analysis (arguably one of the most important optimizations).


#4779344 What are unions good for?

Posted by Jan Wassenberg on 26 February 2011 - 09:54 AM

and pretty much any form of type pruning relies on compiler specific behaviour.

You mean "type punning", for which there are actually two standard and perfectly safe methods - serializing through char*, which has a special dispensation concerning aliasing, or memcpy.

I've seen unions used as a crude reinterpret_cast mechanism in C; not exactly 100% safe, but generally they were not a problem if some precautions were taken.

Is that the way you drive, or want an airline to operate - "not exactly 100% safe, but generally [..] not a problem"?
I don't see why an incorrect and illegal solution is preferable to memcpy, which is hardly more complicated.

Yes that and most of what has been posted here is undefined behaviour according to the standard. You really should have an identifier which signals which element is currently stored in the union, then only read this element and none of the others.

Good advice.

Incidentally, I often engage in bit-twiddling, and have yet to find a helpful and safe use for unions in that context.


PARTNERS