1. A method of transmitting a discovery signal by a device-to-device (D2D) user equipment (UE) in a wireless communication system, the method comprising:determining a size of a sub-period, by the D2D UE, based on a buffer size of a D2D UE receiving the discovery signal in a discovery period; and
transmitting the discovery signal for each of a plurality of sub-periods related with the determined size,
wherein the discovery period is divided into the plurality of the plurality of sub-periods,
wherein the size of the sub-period is determined to minimize the number of subframes not contained in any sub-period in the discovery period, and
wherein the size of the sub-period is determined as follows:
wherein Nbuffer corresponds to the number of subframes stored in the buffer, wherein M corresponds to a size of a sub-period, wherein M? corresponds to a size of the determined sub-period, wherein m corresponds to the number of repetition of the discovery signal, and wherein NP corresponds to the number of subframes contained in a discovery period.