Pointer
@意義: value/address是每個variable的兩個屬性, variable name代表取value, &取address
@功用: 在pass by value的language中, 可以在function內改變function外變數的值, 類似Java中的呼叫instance method其實已隱含this
@重點: 在於address跟value的變換, 1.透過address(pointer)得到value, 2.透過value得到address
int a=5;
int *ptr=&a; // init ptr, 指到a
// pointer的操作
*ptr; // 取a的value
*ptr=7; // 改變a的value
@double pointer:可在function中改變function外pointer的value
int **pp
C/C++的struct跟class
@C struct: 可定義新的type, 但在function call時, 參數傳遞仍為pass by value, 故得傳入pointer才能改變function外面變數的value
@C++ class: 跟C struct相似, 主差別為可讓function成為member及member的access scope; 相同點是在function call時, 預設為pass by value, 所以要改變function外變數的value仍得用pointer,這方面的概念及基礎跟C是相同的
C/C++動態配置memory
@C: 用的是malloc/free
@C++:用的是new/delete
故以下為class variable的動態配置變數obj, 並呼叫其default constructor
Class1 obj = new Class1();
@constructor為一個function, 意義在於幫剛配置的memory initialize, 概念相同於C中變數宣告時得初始化
結論:
1. C++中pointer的概念及基礎設定與 C 相同
2. 參數傳遞方式基礎相同, struct/class的預設為pass by value
3. struct/class概念相似, 同為新增一個type
2013年8月21日 星期三
2013年1月18日 星期五
[Eclipse]attach Javadoc in Eclipse
1. Download Javadoc from oracle.com
2. Open eclipse->Window->Preferences
3. Select Java->Installed JREs
4. Select your installed JDK/JRE, and click enabled "Edit"
5. Select "......\rt.jar" and click enabled "Javadoc Location"
6. Select "Javadoc in archive" and click "Browse" to set your "Archive path".
7. click "Browse" to set your "Path within archive", select the "api" node.
8. click OK and Finish!!
2. Open eclipse->Window->Preferences
3. Select Java->Installed JREs
4. Select your installed JDK/JRE, and click enabled "Edit"
5. Select "......\rt.jar" and click enabled "Javadoc Location"
6. Select "Javadoc in archive" and click "Browse" to set your "Archive path".
7. click "Browse" to set your "Path within archive", select the "api" node.
8. click OK and Finish!!
2012年12月25日 星期二
[Tomcat]org.apache.tomcat.jdbc.pool.ConnectionPool abandon
起因: 使用connection pool用完後一定要close, 否則pool中會殘留idle connection在server未清除, 而導致超過db server 的 max connections限制而得到此訊息
2012年12月2日 星期日
2012年11月13日 星期二
2012年11月11日 星期日
[Eclipse]Eclipse default workspace text encoding
Windows > Preferences > General > Workspaces, set "Text file
encoding" to "Other : UTF-8".
encoding" to "Other : UTF-8".
2012年3月14日 星期三
2012年2月2日 星期四
[SQL Server] 建立連接至 SQL Server 時,發生網路相關或執行個體特定的錯誤。...error: 40 - 無法開啟至 SQL Server 的連接)
錯誤訊息: 建立連接至 SQL Server 時,發生網路相關或執行個體特定的錯誤。找不到或無法存取伺服器。確認執行個名稱是否正確,以及 SQL Server 是否設定為允許遠端連線。 (provider: 具名的管線提供者, error: 40 - 無法開啟至 SQL Server 的連接)
當SQL Browser服務又沒開時
其中一種處理方式:
1. 至SQL Configuration Manager->SQL Server Network Configuration
2. 找到此SQL Server instance的服務-> TCP/IP, 右鍵內容
3. Protocol tab改為enabled, IP Address中的IPAll設定為 1433
4. 這是因為安裝完SQL server後, 並未啟動1433為default port, 故得手動啟動
當SQL Browser服務又沒開時
其中一種處理方式:
1. 至SQL Configuration Manager->SQL Server Network Configuration
2. 找到此SQL Server instance的服務-> TCP/IP, 右鍵內容
3. Protocol tab改為enabled, IP Address中的IPAll設定為 1433
4. 這是因為安裝完SQL server後, 並未啟動1433為default port, 故得手動啟動
2012年1月9日 星期一
2011年12月5日 星期一
[MySQL]乾淨移除MySQL的步驟
1. ‘Uninstall’ mysql from the Control panel.
2. remove the “C:\Program Files\MySQL” folder.
3. Delete the mysql service my using command in command prompt “Sc delete mysql”
4. remove the “C:\Users\pc\AppData\RoaminMySql” folder.
5. Again Reinstall a fresh copy
2. remove the “C:\Program Files\MySQL” folder.
3. Delete the mysql service my using command in command prompt “Sc delete mysql”
4. remove the “C:\Users\pc\AppData\RoaminMySql” folder.
5. Again Reinstall a fresh copy
2011年10月11日 星期二
[DOS] netstat指令
Displays protocol statistics and current TCP/IP network connections.
NETSTAT [-a] [-b] [-e] [-n] [-o] [-p proto] [-r] [-s] [-v] [interval]
-a Displays all connections and listening ports.
-b Displays the executable involved in creating each connection or
listening port. In some cases well-known executables host
multiple independent components, and in these cases the
sequence of components involved in creating the connection
or listening port is displayed. In this case the executable
name is in [] at the bottom, on top is the component it called,
and so forth until TCP/IP was reached. Note that this option
can be time-consuming and will fail unless you have sufficient
permissions.
-e Displays Ethernet statistics. This may be combined with the -s
option.
-n Displays addresses and port numbers in numerical form.
-o Displays the owning process ID associated with each connection.
-p proto Shows connections for the protocol specified by proto; proto
may be any of: TCP, UDP, TCPv6, or UDPv6. If used with the -s
option to display per-protocol statistics, proto may be any of:
IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPv6.
-r Displays the routing table.
-s Displays per-protocol statistics. By default, statistics are
shown for IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6;
the -p option may be used to specify a subset of the default.
-v When used in conjunction with -b, will display sequence of
components involved in creating the connection or listening
port for all executables.
interval Redisplays selected statistics, pausing interval seconds
between each display. Press CTRL+C to stop redisplaying
statistics. If omitted, netstat will print the current
configuration information once.
NETSTAT [-a] [-b] [-e] [-n] [-o] [-p proto] [-r] [-s] [-v] [interval]
-a Displays all connections and listening ports.
-b Displays the executable involved in creating each connection or
listening port. In some cases well-known executables host
multiple independent components, and in these cases the
sequence of components involved in creating the connection
or listening port is displayed. In this case the executable
name is in [] at the bottom, on top is the component it called,
and so forth until TCP/IP was reached. Note that this option
can be time-consuming and will fail unless you have sufficient
permissions.
-e Displays Ethernet statistics. This may be combined with the -s
option.
-n Displays addresses and port numbers in numerical form.
-o Displays the owning process ID associated with each connection.
-p proto Shows connections for the protocol specified by proto; proto
may be any of: TCP, UDP, TCPv6, or UDPv6. If used with the -s
option to display per-protocol statistics, proto may be any of:
IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPv6.
-r Displays the routing table.
-s Displays per-protocol statistics. By default, statistics are
shown for IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6;
the -p option may be used to specify a subset of the default.
-v When used in conjunction with -b, will display sequence of
components involved in creating the connection or listening
port for all executables.
interval Redisplays selected statistics, pausing interval seconds
between each display. Press CTRL+C to stop redisplaying
statistics. If omitted, netstat will print the current
configuration information once.
2011年10月4日 星期二
[Maven]missing artifact com.sun:tools:jar:1.5.0
解決方式: 在pom.xml增加dependency
在local repository依照錯誤建立資料夾, 並將tools.jar置於其中
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
</dependency>
或
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>%jdk path%/lib/tools.jar</systemPath>
</dependency>
在local repository依照錯誤建立資料夾, 並將tools.jar置於其中
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
</dependency>
或
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>%jdk path%/lib/tools.jar</systemPath>
</dependency>
2011年10月3日 星期一
2011年9月5日 星期一
2011年8月30日 星期二
2011年8月11日 星期四
2011年8月10日 星期三
[java]log4j設定
#定義logger "test.board", 這可以以namespace層級方式設定, 如傳入class屬於test.board.aaa, 則會取到此logger
log4j.logger.test.board=debug, A1
#避免讓rootLogger也有重複的輸出, 要加入這一行
log4j.additivity.test.board=false
#設定logger "test.board"顯示在哪種裝置上
log4j.appender.A1=org.apache.log4j.ConsoleAppender
#設定logger "test.board"顯示訊息的格式
log4j.appender.A1.layout.ConversionPattern=%d{ABSOLUTE} %5p [%t] (%F:%L) - %m%n
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.logger.test.board=debug, A1
#避免讓rootLogger也有重複的輸出, 要加入這一行
log4j.additivity.test.board=false
#設定logger "test.board"顯示在哪種裝置上
log4j.appender.A1=org.apache.log4j.ConsoleAppender
#設定logger "test.board"顯示訊息的格式
log4j.appender.A1.layout.ConversionPattern=%d{ABSOLUTE} %5p [%t] (%F:%L) - %m%n
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
"Log4j的關鍵之處在于它的繼承思想。也就是一個Log可以繼承另外一個Log的屬性(輸出到哪里,日誌等級,日誌格式等等)。怎麼繼承?
Log4j是根據Log的名字來判斷繼承關係的,比如:
名字為“com.zhlmmc.lib”的Log就是“com.zhlmmc.lib.log”的parent,明白了吧!Log4j還有一個rootLogger,相當於Java的Object。回過頭來看“LogFactory.getLog(Test.class)”這裏的“Test.class”事實上傳進去的是Test這個類的完整路徑(包名+類名),“test.Test”。這樣如果存在“test”這個Log那麼Test這個Log就繼承它,否則就繼承rootLogger。"
2011年8月8日 星期一
[Visual Studio] *.vshost.exe的用處
轉自http://chuiwenchiu.wordpress.com/2006/04/21/c%E4%B8%80%E5%A0%86-vshost-exe-%E6%98%AF%E5%81%9A%E4%BB%80%E9%BA%BC%E7%94%A8%E5%95%8A/
不知道有沒有人發現 bin/Debug 或 bin/Release 下會出現 [Application Name].vshost.exe,這個檔案是做什麼用的呢?依據官方[1]說法,這個是 Visual Studio 2005 為了以下三個目的所加上去的:
1. 改善除錯效能
2. Partial Trust Debugging:這個沒有用過不太清楚,不過依據文件[1]的描述,好像是為了測試應用程式的安全性必須透過 vshost 來進行初始化…
3. 設計階段可以使用 Immediate Window 進行除錯
簡言之,這個檔案就是為了除錯用。
接下來的問題是,如果程式要出貨想關閉這個功能要怎麼做呢?
只要選取 Project | Properties | Debug,將 Enable the Visual Studio hosting process 選項前的鉤鉤取消即可[3]。
參考資料:
[1] http://msdn2.microsoft.com/en-us/library/ms185331.aspx
[2] http://msdn2.microsoft.com/en-us/library/ms242202.aspx
[3] http://msdn2.microsoft.com/en-us/library/ms185330.aspx
[4] http://blogs.msdn.com/dtemp/archive/2004/08/17/215764.aspx
不知道有沒有人發現 bin/Debug 或 bin/Release 下會出現 [Application Name].vshost.exe,這個檔案是做什麼用的呢?依據官方[1]說法,這個是 Visual Studio 2005 為了以下三個目的所加上去的:
1. 改善除錯效能
2. Partial Trust Debugging:這個沒有用過不太清楚,不過依據文件[1]的描述,好像是為了測試應用程式的安全性必須透過 vshost 來進行初始化…
3. 設計階段可以使用 Immediate Window 進行除錯
簡言之,這個檔案就是為了除錯用。
接下來的問題是,如果程式要出貨想關閉這個功能要怎麼做呢?
只要選取 Project | Properties | Debug,將 Enable the Visual Studio hosting process 選項前的鉤鉤取消即可[3]。
參考資料:
[1] http://msdn2.microsoft.com/en-us/library/ms185331.aspx
[2] http://msdn2.microsoft.com/en-us/library/ms242202.aspx
[3] http://msdn2.microsoft.com/en-us/library/ms185330.aspx
[4] http://blogs.msdn.com/dtemp/archive/2004/08/17/215764.aspx
2011年7月21日 星期四
[JMS] MessageListener.onMessage
A client can register an object that implements the JMS MessageListener interface with a MessageConsumer. As messages arrive for the consumer, the provider delivers them by calling the listener’s onMessage method.
It is possible for a listener to throw a RuntimeException; however, this is considered a client programming error. Well-behaved listeners should catch such exceptions and attempt to divert messages causing them to some form of application-specific ‘unprocessable message’ destination.
The result of a listener throwing a RuntimeException depends on the session’s acknowledgment mode.
AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE - the message will be immediately redelivered. The number of times a JMS provider will redeliver the same message before giving up is provider-dependent. The JMSRedelivered message header field will be set for a message redelivered under these circumstances.
CLIENT_ACKNOWLEDGE - the next message for the listener is delivered. If a client wishes to have the previous unacknowledged message redelivered, it must manually recover the session.
Transacted Session - the next message for the listener is delivered. The client can either commit or roll back the session (in other words, a RuntimeException does not automatically rollback the session).
JMS providers should flag clients with message listeners that are throwing RuntimeExceptions as possibly malfunctioning.
It is possible for a listener to throw a RuntimeException; however, this is considered a client programming error. Well-behaved listeners should catch such exceptions and attempt to divert messages causing them to some form of application-specific ‘unprocessable message’ destination.
The result of a listener throwing a RuntimeException depends on the session’s acknowledgment mode.
AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE - the message will be immediately redelivered. The number of times a JMS provider will redeliver the same message before giving up is provider-dependent. The JMSRedelivered message header field will be set for a message redelivered under these circumstances.
CLIENT_ACKNOWLEDGE - the next message for the listener is delivered. If a client wishes to have the previous unacknowledged message redelivered, it must manually recover the session.
Transacted Session - the next message for the listener is delivered. The client can either commit or roll back the session (in other words, a RuntimeException does not automatically rollback the session).
JMS providers should flag clients with message listeners that are throwing RuntimeExceptions as possibly malfunctioning.
訂閱:
文章 (Atom)