Arup Banerjee

June 21, 2014

AutoResetEvent

Filed under: Threading — arupbanerjee @ 6:32 pm

Two important notes

There is no guarantee that every call to the Set method will release a thread. If two calls are so close together that the second call occurs before a thread has been released, only one thread is released. It is as if the second call did not occur.

Also, if Set is called when there are no threads waiting and the AutoResetEvent is already signaled, the call has no effect.

 If Set is called when no thread is waiting, the handle stays open for as long as it takes until some thread calls WaitOne. This behavior helps avoid a race between a thread heading for the turnstile, and a thread inserting a ticket (“Oops, inserted the ticket a microsecond too soon, bad luck, now you’ll have to wait indefinitely!”). However, calling Set repeatedly on a turnstile at which no one is waiting doesn’t allow a whole party through when they arrive: only the next single person is let through and the extra tickets are “wasted.” http://www.albahari.com/threading/part2.aspx#%5FProducerConsumerQWaitHandle

May 25, 2012

VB How to check modified elements in dataset

Filed under: VB UI — arupbanerjee @ 11:17 am

PrivateSub

UpdateChanges()

 

 

 

‘If ds.HasChanges() Then

 

 

 

 

‘ Dim result As DialogResult = MessageBox.Show(“Do you want to save your changes”, “Warning”, MessageBoxButtons.YesNo)

 

 

 

 

‘ If result = Windows.Forms.DialogResult.Yes Then

 

 

 

 

‘ daCFTC.Update(ds)

 

 

 

 

‘ End If

 

 

 

 

‘End If

 

 

 

 

‘Return True

 

 

Me.BindingContext(ds, “SELECT_CFTC_PRODUCTS”

).EndCurrentEdit()

 

If ds.HasChanges()

 

Then

 

 

Dim result AsDialogResult = MessageBox.Show(“Do you want to save your changes”, “Warning”, MessageBoxButtons

.YesNo)

 

If result = Windows.Forms.DialogResult.Yes

 

Then

 

 

 

 

‘daCPPLC.Update(ds)

 

 

 

 

‘ Check for changes with the HasChanges method first.

 

 

IfNot ds.HasChanges(DataRowState.Modified) Then

 

Exit Sub

 

 

 

 

‘ Create temporary DataSet variable.

 

 

Dim xDataSet As

 

DataSet

 

 

 

 

‘ GetChanges for modified rows only.

 

 

xDataSet = ds.GetChanges(

DataRowState

.Modified)

 

 

 

‘ Check the DataSet for errors.

 

 

If xDataSet.HasErrors Then

 

Exit Sub

 

 

ForEach row AsDataRowIn

xDataSet.Tables(0).Rows

 

Dim product = row(“PRODUCT”

)

 

Dim limit = row(“LIMIT”

)

 

Dim single_limit = row(“Single_Limit”

)

 

Dim Product_Group = row(“PRODUCT_GROUP”

)

 

Dim Multiplier = row(“MULTIPLIER”

)

cftc.Set_UPDATE_CFTC_PRODUCTS(product, limit, single_limit, Product_Group, Multiplier)

 

 

 

 

Next

 

 

End

 

If

 

 

End

 

If

 

 

 

End

 

Sub

 

 

May 24, 2012

Oracle append hint insert /*+ append */ into ….

Filed under: Database — arupbanerjee @ 9:44 am

 

Insert /*+ APPEND */ – why it would be horrible for Oracle to make that the “default”.

a) it isn’t necessarily faster in general. It does a direct path load to disk – bypassing the buffer cache. There are many cases – especially with smaller sets – where the direct path load to disk would be far slower than a conventional path load into the cache.

b) a direct path load always loads above the high water mark, since it is formatting and writing blocks directly to disk – it cannot reuse any existing space. Think about this – if you direct pathed an insert of a 100 byte row that loaded say just two rows – and you did that 1,000 times, you would be using at least 1,000 blocks (never reuse any existing space) – each with two rows. Now, if you did that using a conventional path insert – you would get about 70/80 rows per block in an 8k block database. You would use about 15 blocks. Which would you prefer?

c) you cannot query a table after direct pathing into it until you commit.

d) how many people can direct path into a table at the same time? One – one and only one. It would cause all modifications to serialize. No one else could insert/update/delete or merge into this table until the transaction that direct paths commits.

Direct path inserts should be used with care, in the proper circumstances. A large load – direct path. But most of the time – conventional path.

 

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1211797200346279484

 

 

May 16, 2012

Oracle DDL (Truncate Create etc) in SP require execute immediate

Filed under: Database — Tags: — arupbanerjee @ 7:28 am

plsql to create, insert into, fetch from and drop a temporary table — whose name is not
known until run time.

SQL> declare
  2      type mycur is ref cursor;
  3 
  4      l_tname     varchar2(30) default ‘temp_table_’ || userenv(‘sessionid’);
  5      l_cursor    mycur;
  6      l_ename     scott.emp.ename%type;
  7  begin
  8      execute immediate ‘create global temporary table ‘ ||
  9                         l_tname || ‘ on commit delete rows
10                         as
11                         select * from scott.emp where 1=0 ‘;
12 
13      execute immediate ‘insert into ‘ || l_tname ||
14                        ‘ select * from scott.emp’;
15 
16      open l_cursor for
17          ‘select ename from ‘ || l_tname || ‘ order by ename’;
18 
19      loop
20          fetch l_cursor into l_ename;
21          exit when l_cursor%notfound;
22          dbms_output.put_line( l_ename );
23      end loop;
24 
25      close l_cursor;
26      execute immediate ‘drop table ‘ || l_tname;
27  end;

http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:48812348054

December 23, 2011

OSQL

Filed under: Uncategorized — arupbanerjee @ 4:17 pm

osql -S LDNDCM05980V05B\CRE_MAIN1_DEV -d core -E -h-1 -w 10000 -Q”SET NOCOUNT ON;select * from EnvironmentParms” -o envparams.txt -s” “

February 22, 2011

When to use Lambda Any or Contains()

Filed under: Lambda — arupbanerjee @ 5:13 pm

Note there is a good website which checked the performance metrics of Any<> and Contains.

http://www.tkachenko.com/blog/archives/000682.html

But the question is when to choose Any<> even tho its perf is quite slow.

Well contains is more like static, whereas Any<> builds dynamic lambda in memory.

Say you have a collection of objects and you want to filter based on a property value of the object contained rather than the object itself.

In such cases you are best off to use Any<>

June 9, 2010

FX Delta due to Imputed Dividends

Filed under: Business — arupbanerjee @ 1:28 pm

Imputed dividends are system related rather than natural dividends.

Say you have

@ Time T0 ==> 1000 shares worth 100 p so total £1000/-

@ Time T1 (Dividend event) ==> 1000 shares worth 100p plus 10p div so total value £1000/-    +  £100/- . But actually the £100 does not hit the account on this day. So the system will impute this

@Time T2 (Dividend) hits the account so 1000 shares worth 100p plus 10p div so total value £1000/-    +  £100/- . Total.

Now at T1 we know that we are getting div of £100.  So if we are dollar based bank we will expect the rate  for £ to increase although we do not have the amount still in our account. Hence we have exposure due to imputed dividends and should be inlcuded into the total delta exposure

                                

October 10, 2009

VS 2008 Version Conflict

Filed under: Uncategorized — arupbanerjee @ 7:36 am

I faced a problem , when I was repeatedly trying to incude a assembly from a localtion , but it was taking it from a different location, the one in GAC.

VS resolve conflict did not resolve the issue until the removed the entry of that assembly in the csproj as below

<

Reference Include=PresentationFramework />

<

Reference Include=MyAssembly />

February 15, 2009

C# Exception Facts

Filed under: C# .Net 2.0 Techniques — arupbanerjee @ 12:44 pm

What is an Exception

Popular misconception , Exception does not mean Error Handling …..

When an type’s action member cannot complete its task, the member should throw an exception. An exception means that an action member failed to complete its task it was supposed to perform indicated by its name.

internal class Account {

public static void Transfer(Account from, Account to , Decimal amount) { … }

}

Here is for some reason Transfer cannot happen then it should throw an exception.

What’s the order of inner finally when an exception occurs on an outer try block.

   CLR  first locates the catch block with a matching catch type, it executes the code in the inner finally blocks, starting from within the try block whose code threw the exception and stopping with the catch block that matched the exception.

Note that any finally block associated with the catch block that matched the exception is not executed yet. The code in this finally block won’t execute until after the code in the handling catch block is executed.

What happens if code in finally block throws an exception.

  CLR will not keep track of the first exception.

Whats difference between

try{ … }

catch(Exception e)

{

throw e; // CLR resets the starting point of exception to here

}

catch(Exception e)

{

throw; //CLR will keep the original location of exception

}

Why sometimes actual call stack don’t appear in the stack trace string

JIT compiler can inline method

October 26, 2008

Difference const iterator and const_iterator

Filed under: C++ Techniques, STL — arupbanerjee @ 12:50 pm

STL iterators are modeled on pointers, so an iterator acts much like a T* pointer. Declaring an iterator const is like declaring a pointer const (i.e., declaring a T* const pointer): the iterator isn’t allowed to point to something different, but the thing it points to may be modified. If you want an iterator that points to something that can’t be modified (i.e., the STL analogue of a const T* pointer), you want a const_iterator:

std::vector<int> vec;

...

const std::vector<int>::iterator iter =     // iter acts like a T* const

  vec.begin();

*iter = 10;                                 // OK, changes what iter points to

++iter;                                    // error! iter is const

std::vector<int>::const_iterator cIter =   //cIter acts like a const T*

  vec.begin();

*cIter = 10;                               // error! *cIter is const

++cIter;                                  // fine, changes cIter
Older Posts »

Create a free website or blog at WordPress.com.