말랑말랑한 이야기2010. 10. 16. 06:40

Saving ASP VBScript "Objects" to Session (Tuesday, March 08, 2005)
Continuing my trouble and hatred of anything todo with Visual Basic, especially VBScript.  In this episode of The VB Sucks Edition, I'll reivew the problem with VBScript "Objects”.  As any programmer knows, VBScript was never meant to be object-oriented, but by VBS 5, someone at Microsoft thought they could try to make it a bit OO compatible.  The introduction of VBS classes was a major step in that direction.  This seems like a good idea, but instead of making real objects, Microsoft hacked together classes that really mean nothing.  Let me explain.

VBS objects are not really stored in memory as objects.  For this reason, it is not possible to store a VBS object in the Session or Application variables in ASP.  This creates huge headaches, and is completely rediculous.  There are however, some solutions.

The first solution is "Serializing" your class.  You will not truely be serializing anything, but rather creating a "seralize" and "deserialize" method for each class that you declare.  These methods will take a Session variable name as a parameter and "store" or "retrieve" a class from session.  See the example below.

Class MyClass
     Dim Var1
     Dim Var2
End Class

Function Serialize_MyClass( instance, sessionVar )
     Session( sessionVar & ".Var1" ) = instance.Var1
     Session( sessionVar & ".Var2" ) = instance.Var2
End Function

Function Deserialize_MyClass(sessionVar)
     Dim instance : Set instance = new MyClass
     instance.Var1 = Session( sessionVar & ".var1" )
     instance.Var2 = Session( sessionVar & ".var2" )

     Set Deserialize_MyClass = instance
End Function

This solution will work if you must keep all your code in VBScript, however is quite a pain to implement.  If you can mix JScript into your code, I suggest using the following solution.

The other way of saving objects to session in ASP is not to use VBScript objects, but use JScript objects instead.  Because of the way JScript creates objects, you can save JS objects to Session.  By declaring your class in JS, you can keep your code (somewhat) clean, and still have the ability to save your objects.  See below for an example.

<script runat="server" language="jscript">

function MyClass()
{
   this.Var1 = Var1;
   this.Var2 = Var2;
}

var Var1, Var2;

function MyClassFactory()
{
   return new MyClass();
}

</script>

Using script like the one above allows you to keep your class declarations clean, and removes the need for "serialization” functions.  The only problem that still remains is VBScript can't declare instances of JScript classes (even though it can use them).  For this reason, I suggest using a factory function in JScript for your classes (such as MyClassFactory in the example above).  Because VBScript can call JScript functions, you will be able to get a new instance of the JScript class into your VB code, as shown below.

Dim instance : instance = MyClassFactory()
instance.Var1 = "12345"


So there you have it, the half-ass hack to solve the problem of saving classes to Session or Application variables to the piece of junk that is VBScript.

Filed under:
Posted by Ditongs Ditongs

댓글을 달아 주세요

말랑말랑한 이야기2010. 9. 9. 20:28

Sunday, May 30, 2010

The limitations of AsyncTask

AsyncTask is a fine API, it's been said that it "holds your hand", and makes performing background operations painless. It pulls this off so well in fact, that I see people overusing it in situations where it's not really appropriate.

It's particularly unsuited for situations when you have a multiple tasks to perform concurrently. Imagine an Activity that needs to download about 30 small images from a remote server, and update the UI as these become available. AsyncTask uses a static internal work queue with a hard-coded limit of 10 elements. That means if you were to create an AsyncTask instance for each image, the work queue would quickly overflow and many of your tasks would get rejected. The best solution in this case is to create your own ThreadPoolExecutor instance that uses a queue that's large enough to hold all your tasks, if you need an unbounded queue, a LinkedBlockingQueue will work just fine.

Another severe limitation is that an AsyncTask can't survive your Activity being torn down and recreated on the other side.  Even if you pass it to the new instance via onRetainNonConfigurationState, the internal Handler inside the AsyncTask is still going to be stale and it's not going to behave correctly.  This is important to consider, and the Android documentation makes no mention of it all.  I've already blogged this scenario in detail, so I won't flog a dead horse here.

There are a few other minor issues, such as the fact that you can't change the background threads execution priority. It's hard-coded to a low priority, which granted, is the sensible default.  Also, exception handling is not very well supported.

So just to reiterate, AsyncTask is a nice API, but you should understand it's limitations and apply it appropriately.  If you're serious about writing mobile apps, then you're going to need a few more tools in the toolbox to get the job done.

Source: http://foo.jasonhudgins.com/2010/05/limitations-of-asynctask.html

Posted by Ditongs Ditongs

댓글을 달아 주세요

  1. It can accommodate 13 passengers and fly for 3, http://www.moncleroutletespain.com/ moncler españa,250 nautical miles without refueling. Passengers can fly non-stop from New York to London. Cabin features include executive leather seats, http://www.moncleroutletespain.com/ moncler, a divan and credenza, tables for group meals or meetings, http://www.moncleroutletespain.com/ moncler outlet, individual tables, a galley, http://www.moncleroutletespain.com/ moncler online, an enclosed lavatory, a wardrobe/storage cabinet, http://www.moncleroutletespain.com/ moncler chaquetas, a DVD player with two different sized LCD monitors and a voice/data communication system. So the next time you're flying, http://www.moncleroutletespain.com/ http://www.moncleroutletespain.com/, request the Embraer Legacy and get a taste of flying in real luxury for less!Related articles:


    http://hiddenchampion.tistory.com/741 http://hiddenchampion.tistory.com/741

    http://mba7.tistory.com/59 http://mba7.tistory.com/59

    2013.01.05 16:56 [ ADDR : EDIT/ DEL : REPLY ]

딱딱한 이야기2010. 8. 24. 05:08

우연히 손에 잡혀 읽게 된 책입니다. "무소유"를 읽고 난 직후에 집어든 책인데요. 저랑 인연이 닿은 모양입니다. 아무튼 요즘 느끼는 이슈랑 딱 맞아 떨어졌습니다. 저는 마켓 3.0 시대를 응원하고 있습니다. 잘 만든 백편의 광고보다 영향력 있는 한명의 블로거 글이 더 효과가 있는 세상이 온거죠. 인터넷을 등에 업고요. 스마트폰의 보급과 함께 마켓 3.0은 더욱 가속화 될 것 입니다. 마켓 4.0은 과연 어떤 모습일까요?

'딱딱한 이야기' 카테고리의 다른 글

네트워크 용량 - 카페24  (0) 2020.03.23
Market 3.0  (0) 2010.08.24
Matrix  (0) 2010.08.24
Posted by Ditongs Ditongs

댓글을 달아 주세요