Posts Tagged string

The Four Vector Classes

Tags: , , , , , , , ,

There are four Vector classes in AS3. It seems like there is only one—Vector—and that it supports generics, but that is only an illusion. Today’s article will do some tests to reveal the implications to your app’s correctness and efficiency.

Read the rest of this article »

3 Comments

Multi-Line Strings

Tags: , ,

AS3 has never had very good support for multi-line strings… until now. Today’s article discusses the proper and improper ways of writing multi-line strings and delves into the bytecode so you really understand what’s going on.

Read the rest of this article »

14 Comments

How To Fix the XML Memory “Leak”

Tags: , , , , , ,

Dealing with XML files can very easily trigger Flash to “leak” memory. Your app may only keep a tiny fraction of the XML file’s contents, but the whole file may stay in memory and never get garbage collected. Today’s article examines how this happens and how you can clean up all that unused memory.

Read the rest of this article »

20 Comments

String.charCodeAt Is Really Fast

Tags: , , ,

String.charCodeAt is a simple function so you might expect the function call overhead (huge in AS3) to making calling it frequently quite slow. You’d think that there’s no way an charCodeAt-using AS3 function could beat a built-in String function like indexOf. Would you be right? Today’s article examines this special function to see if we might defy conventional wisdom and achieve a performance boost.

Read the rest of this article »

4 Comments

String-Sortable Integers

Tags: , , , ,

Strings and integers sort differently. Unfortunately, this became a problem for me during some recent experiments with Starling. It could be a problem for you too in a variety of situations. Today we’ll look at a workaround I’ve developed to solve this problem, which isn’t nearly as straightforward as you might think.

Read the rest of this article »

7 Comments

Utility Function: indexedTrisToString

Tags: , , , , , ,

This week’s article offers another useful utility function: indexedTrisToString. This function is especially useful when dealing with 3D engines such as those based on Context3D.drawTriangles or Graphics.drawTriangles. It helps to untangle the complicated indices/vertices format that these API functions require into something much more readable and, therefore, debuggable.

Read the rest of this article »

No Comments

Utility Functions: joinN and joinNLabeled

Tags: , , , , , ,

It’s been a while since I’ve posted a utility function, but today I’m breaking the streak and posting a couple of related functions I frequently find useful in debugging: joinN and joinNLabeled. These functions are like Array.join and Vector.join, but they group elements of the array to make the resulting string much easier to read.

Read the rest of this article »

7 Comments

Building Strings

Tags: , , , , , , , ,

When a recent comment asked about string concatenation performance, I realized that there are a lot of ways to build strings in AS3 and I hadn’t tested any of them. Leaving aside the sillier ones like the XML class or joining Array objects, we have two serious contenders: the lowly + operator (i.e. str + str) and the ByteArray class. Which will triumph as the ultimate way to build strings quickly?

Read the rest of this article »

18 Comments

Hidden Object Allocations

Tags: , , , , , , , , , , , , , ,

During some recent memory profiling I was reacquainted with just how many ways there are to unknowingly allocate an object in AS3. The problem is seldom the allocation itself, but rather the later garbage collection (GC) to delete those objects. Ever used a Flash profiler only to see a huge chunk of your CPU time going to [reap], [mark], or [sweep]? Yeah, that’s the GC at work. Today’s article talks about some of the ways you end up allocating objects in AS3 without using the new keyword. These subtle errors can end up costing you!

Read the rest of this article »

28 Comments

Explicit Type Conversion

Tags: , , , , , , ,

Five months ago I said I’d talked about explicit type conversion. I hadn’t, really. What I talked about before was type casts. A cast changes the type, not the data. Today, I’m actually going to talk about type conversion and show you the costs of converting between all of your favorite types: int, uint, Number, Boolean, String, and even XML.

Read the rest of this article »

4 Comments